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


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM