我要打开该文件
IntelliJ IDEA Community Edition 14.0.3\examples\assigment_4\src\file.txt
使用以下代码:
BufferedReader hangmanWordsFromFile = new BufferedReader(new FileReader("file.txt"));
但它抛出异常
java.io.FileNotFoundException: HangmanLexicon.txt (The system cannot find the file specified)
当我将file.txt
复制到
IntelliJ IDEA Community Edition 14.0.3\jre\jre\bin
它有效。
打印 System.getProperty("user.dir")
生成 IntelliJ IDEA Community Edition 14.0.3\jre\jre\bin
。
如何更改 user.dir
路径,以便可以使用 file.txt
作为文件名来打开位于 IntelliJ IDEA Community Edition 14.0 的文件.3\examples\assigment_4\src\
?
最佳答案
您应该配置您的 working directory :
转到运行 > 编辑配置
,选择运行配置并选择工作目录(file.txt 所在的目录)。
关于java - 如何仅使用 INTELLIJ 中的文件名打开 src 目录中的文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29280348/