1. BIO

2. NIO

3. AIO

4. 文件读取

class.getClassLoader().getResourceAsStream() 和 class.getResouceAsStream() 的区别

  • class.getClassLoader().getResourceAsStream(String name) 默认从classpath中找文件(文件放在resources目录下),name不能带”/“,否则会抛空指针。采用相对路径, “/“就相当于当前进程的根目录,即项目根目录;

    1. inStream = PropertiesTest.class.getClassLoader().getResourceAsStream("com/test/demo/test.properties");
  • class.getResourceAsStream(String name) 是采用绝对路径,绝对路径是相对于 classpath 根目录的路径,”/“ 就代表着 classpath,所以 name 属性需要前面加上 “/“;

    1. inStream = PropertiesTest.class.getResourceAsStream("/com/test/demo/test.properties")