获取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"));

相关文章:

  • 2021-12-27
  • 2021-12-23
  • 2021-12-06
  • 2022-01-08
  • 2022-01-30
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-05-18
  • 2022-01-17
  • 2022-12-23
  • 2022-12-23
  • 2021-07-14
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案