IntelliJ IDEA 专注IntelliJ IDEA经验分享

IntelliJ 将非 java 文件拷贝至编译后的目录

2016-12-13  本文已影响30人  专职跑龙套

IntelliJ 默认将编译后的 .class 文件拷贝至编译后的目录,不包括其他文件,例如 .txt 文件。

所以如下默认的代码可能会抛出异常:(即使 a.txt 在同一个目录下)
java.io.FileNotFoundException: a.txt (The system cannot find the file specified)

public static void main(String[] args) throws Exception {
    InputStream fin = new FileInputStream("./a.txt");

    System.out.println(fin.available());
}

解决方案:
File -> Setting -> Compiler -> Resource Patterns
添加 txt
如图所示:

IntelliJ Setting
上一篇 下一篇

猜你喜欢

热点阅读