老兄,你这那是有一个错误:
1. public FileIODemo构造函数少括号。
2. int data;没有被定义;
3. fin和fout被重复定义;
4. System.in和System.out用法不对。
1. public FileIODemo构造函数少括号。
2. int data;没有被定义;
3. fin和fout被重复定义;
4. System.in和System.out用法不对。
调试欢乐多
FileOutStream->
FileOutputStream。
你的FileInputStream的参数不能是System.in;因为System.in是一个InputStream的实例,而FileInputStream的构造方法的参数没有InputStream。这个你可以查阅Sun的JDK文档,获得具体信息。
class FileIODemo
{
public static void main(String args[])
{
FileIODemo aFileIODemo=new FileIODemo();
};
public FileIODemo()
{
try
{
FileInputStream fin=new FileInputStream(System.in);
FileOutputStream fout=new FileOutputStream(new File("input.txt"));
int nKeyIn;
for(int n=0;n<10;n++)
{
nKeyIn=fin.read();
fout.write(nKeyIn);
}
fout.close();
// FileInputStream fin=new FileInputStream(new File("input.txt"));
//FileOutputStream fout=new FileOutputStream(System.out);
while(fin.available()>0)
{
nKeyIn=fin.read();
fout.write(nKeyIn);
}
fin.close();
fout.close();
}
catch(FileNotFoundException e)
{
e.printStackTrace();
}
catch(IOException exp)
{
exp.printStackTrace();
}
};
}