我正在尝试运行从 Sun Java 站点获取的代码(我没有复制它,查看并编写它,因为它可以帮助我记住代码)。
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
public class CharEx{
FileReader inputStream = null;
FileWriter outputStream = null;
public static void main(String args[]) throws IOException{
FileReader inputStream = null;
FileWriter outputStream = null;
try{
inputStream = FileReader("xanadu.txt");
outputStream = FileWriter("out.txt");
int c;
while ((c = inputStream.read()) != -1){
outputStream(c);
}
}
finally{
if(inputStream !=null){
inputStream.close();
}
if(outputStream !=null){
outputStream.close();
}
}
}
}
但是我遇到了以下错误。
D:\Java>javac CharEx.java
CharEx.java:14: cannot find symbol
symbol : method FileReader(java.lang.String)
location: class CharEx
inputStream = FileReader("xanadu.txt");
^
CharEx.java:15: cannot find symbol
symbol : method FileWriter(java.lang.String)
location: class CharEx
outputStream = FileWriter("out.txt");
^
CharEx.java:18: cannot find symbol
symbol : method outputStream(int)
location: class CharEx
outputStream(c);
^
3 errors
从消息中我认为系统正在寻找FileReader
内部java.lang
,而它应该在内部寻找它java.io.*
:((
有人可以帮我在哪里出错吗?
PS:我在 JDK 1.5 上。