下面是代码:
import java.io.*;
public class Copy{
public static void main(String[] args)throws IOException{
File inputFile=new File("abc.txt");
File outputFile=new File("cba.txt");
FileReader in=new FileReader(inputFile);
FileWriter out=new FileWriter(outputFile);
int c;
while((c=in.read())!=-1){
out.write(c);
}
in.close();
out.close();
}
}
以下是运行结果:
e:\Java>javac Copy.java
e:\Java>java Copy
Exception in thread "main" java.io.FileNotFoundException: abc.txt (系统找不到指
定的文件。)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(FileInputStream.java:106)
at java.io.FileReader.<init>(FileReader.java:55)
at Copy.main(Copy.java:7)
------解决方案--------------------------------------------------------
File inputFile=new File("abc.txt");
File outputFile=new File("cba.txt");
这两句改成这样
File inputFile=new File("C:/abc.txt");
File outputFile=new File("C:/cba.txt");