File io Intellij文件类路径

File io Intellij文件类路径,file-io,intellij-idea,classpath,File Io,Intellij Idea,Classpath,在Intellij中,文件位于类路径资源文件夹中,该文件夹也标记为资源。 但是,当我使用: new FileInputStream("myFile.xml"); 我得到: java.io.FileNotFoundException: myFile.xml (No such file or directory) 我错在哪里?如果您的myFile.xml位于resources文件夹中,请提前感谢 试着这样读 InputStream inputStream = YourClassName.

在Intellij中,文件位于类路径资源文件夹中,该文件夹也标记为资源。 但是,当我使用:

new FileInputStream("myFile.xml");
我得到:

java.io.FileNotFoundException: myFile.xml (No such file or directory)

我错在哪里?如果您的myFile.xml位于resources文件夹中,请提前感谢

试着这样读

    InputStream inputStream = YourClassName.class.getResourceAsStream("/myFile.xml");
    BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream));