我试过了,它对我有用。
我的Test1类位于默认程序包中,只需检查您访问的类在任何程序包中的位置,然后将其从类路径返回至确切的资源文件夹,例如“ ../”。
public class Test1 { public static void main(String[] args) { new Test1(); } Test1(){ BufferedInputStream file= (BufferedInputStream) this.getClass().getResourceAsStream("resources/a.txt"); try { System.out.println((char)file.read()); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }}


