java.io.FileNotFoundException: read.txt(系统找不到指定的文件)`
java.io.FileNotFoundException: read.txt (The system cannot find the file specified)`
当我尝试 运行 时,我总是遇到这个错误:
IOException: java.io.FileNotFoundException: read.txt (The system cannot find the file specified)
这是我的代码片段:
try(BufferedReader in = new BufferedReader(new FileReader("read.txt"));
BufferedWriter out = new BufferedWriter(new FileWriter("write.txt"))){
String l;
while((l=in.readLine())!=null)
out.write(l);
}
catch(IOException e){System.out.println("IOException: "+e);}
更多 我正在使用 Netbeans 8.0.1。我已经在这个站点上进行了一些类似的查询,并尝试将上面提到的 read.txt 与 src 文件夹以及 class 文件一起放在其中。但我仍然收到此错误。有人可以指出我的错误吗?
我刚刚在尝试构建项目时注意到了这一点。我是新手所以不明白这是否与我的问题有关
ant -f "E:\Programming\Projects\java files\JavaNio1_3" -Dnb.internal.action.name=rebuild clean jar
init:
deps-clean:
Updating property file: E:\Programming\Projects\java files\JavaNio1_3\build\built-clean.properties
Deleting directory E:\Programming\Projects\java files\JavaNio1_3\build
clean:
init:
deps-jar:
Created dir: E:\Programming\Projects\java files\JavaNio1_3\build
Updating property file: E:\Programming\Projects\java files\JavaNio1_3\build\built-jar.properties
Created dir: E:\Programming\Projects\java files\JavaNio1_3\build\classes
Created dir: E:\Programming\Projects\java files\JavaNio1_3\build\empty
Created dir: E:\Programming\Projects\java files\JavaNio1_3\build\generated-sources\ap-source-output
Compiling 1 source file to E:\Programming\Projects\java files\JavaNio1_3\build\classes
Copying 2 files to E:\Programming\Projects\java files\JavaNio1_3\build\classes
compile:
Created dir: E:\Programming\Projects\java files\JavaNio1_3\dist
Copying 1 file to E:\Programming\Projects\java files\JavaNio1_3\build
Nothing to copy.
Building jar: E:\Programming\Projects\java files\JavaNio1_3\dist\JavaNio1_3.jar
To run this application from the command line without Ant, try:
java -jar "E:\Programming\Projects\java files\JavaNio1_3\dist\JavaNio1_3.jar"
jar:
BUILD SUCCESSFUL (total time: 0 seconds)
只需阅读异常的详细信息即可自行解释 here:
A file with the specified pathname does not exist
即 VM
没有找到您在 FileReader
中指定的任何文件。
您的 read.txt
文件应该在 NetBeans 项目目录中,例如
C:\Users\ABC\Documents\NetBeansProjects\Sample\read.txt
驱动器中带有测试文件的示例代码:
try(BufferedReader in = new BufferedReader(new FileReader("D:\MyTasks.txt"));
BufferedWriter out = new BufferedWriter(new FileWriter("write.txt"))){
String l;
while((l=in.readLine())!=null)
out.write(l);
}
catch(IOException e){System.out.println("IOException: "+e);}
谢谢大家的帮助。终于解决了!
我尝试了 kakurala 在上面的评论中提到的方法并且成功了!
"create file with java and then check whether it is creating in project directory or somewhere else. – kakurala"
谢谢大佬..感谢大家花时间回答。
现在可以关闭此线程:)
当我尝试 运行 时,我总是遇到这个错误:
IOException: java.io.FileNotFoundException: read.txt (The system cannot find the file specified)
这是我的代码片段:
try(BufferedReader in = new BufferedReader(new FileReader("read.txt"));
BufferedWriter out = new BufferedWriter(new FileWriter("write.txt"))){
String l;
while((l=in.readLine())!=null)
out.write(l);
}
catch(IOException e){System.out.println("IOException: "+e);}
更多 我正在使用 Netbeans 8.0.1。我已经在这个站点上进行了一些类似的查询,并尝试将上面提到的 read.txt 与 src 文件夹以及 class 文件一起放在其中。但我仍然收到此错误。有人可以指出我的错误吗?
我刚刚在尝试构建项目时注意到了这一点。我是新手所以不明白这是否与我的问题有关
ant -f "E:\Programming\Projects\java files\JavaNio1_3" -Dnb.internal.action.name=rebuild clean jar
init:
deps-clean:
Updating property file: E:\Programming\Projects\java files\JavaNio1_3\build\built-clean.properties
Deleting directory E:\Programming\Projects\java files\JavaNio1_3\build
clean:
init:
deps-jar:
Created dir: E:\Programming\Projects\java files\JavaNio1_3\build
Updating property file: E:\Programming\Projects\java files\JavaNio1_3\build\built-jar.properties
Created dir: E:\Programming\Projects\java files\JavaNio1_3\build\classes
Created dir: E:\Programming\Projects\java files\JavaNio1_3\build\empty
Created dir: E:\Programming\Projects\java files\JavaNio1_3\build\generated-sources\ap-source-output
Compiling 1 source file to E:\Programming\Projects\java files\JavaNio1_3\build\classes
Copying 2 files to E:\Programming\Projects\java files\JavaNio1_3\build\classes
compile:
Created dir: E:\Programming\Projects\java files\JavaNio1_3\dist
Copying 1 file to E:\Programming\Projects\java files\JavaNio1_3\build
Nothing to copy.
Building jar: E:\Programming\Projects\java files\JavaNio1_3\dist\JavaNio1_3.jar
To run this application from the command line without Ant, try:
java -jar "E:\Programming\Projects\java files\JavaNio1_3\dist\JavaNio1_3.jar"
jar:
BUILD SUCCESSFUL (total time: 0 seconds)
只需阅读异常的详细信息即可自行解释 here:
A file with the specified pathname does not exist
即 VM
没有找到您在 FileReader
中指定的任何文件。
您的 read.txt
文件应该在 NetBeans 项目目录中,例如
C:\Users\ABC\Documents\NetBeansProjects\Sample\read.txt
驱动器中带有测试文件的示例代码:
try(BufferedReader in = new BufferedReader(new FileReader("D:\MyTasks.txt"));
BufferedWriter out = new BufferedWriter(new FileWriter("write.txt"))){
String l;
while((l=in.readLine())!=null)
out.write(l);
}
catch(IOException e){System.out.println("IOException: "+e);}
谢谢大家的帮助。终于解决了!
我尝试了 kakurala 在上面的评论中提到的方法并且成功了!
"create file with java and then check whether it is creating in project directory or somewhere else. – kakurala"
谢谢大佬..感谢大家花时间回答。
现在可以关闭此线程:)