获取InputStream对象的方法

获取InputStream对象的方法

  1. getResourceAsStream(String path)

默认path路径位于Class所在Module的src目录下 .

InputStream is = ClassLoader.getSystemClassLoader().getResourceAsStream("jdbc.properties");

  1. FileInputStream("String name")

在main方法中时, 默认路径为为Project下; 在@Test单元测试方法中路径为当前Class所在Module目录下 .

FileInputStream is = new FileInputStream("jdbc.properties");
  1. FileInputStream(new File(String pathName))

与上面的方法相同.在main方法中时, 默认路径为为Project下;在@Test单元测试方法中路径为当前Class所在Module目录下 .

FileInputStream is = new FileInputStream(new File("InputStream\\src\\hi.txt"));
posted @ 2020-06-12 15:04  juyss  阅读(1684)  评论(2编辑  收藏  举报