import java.io.*;
class FileReaderDemo
{
public static void main(String[] args) throws IOException
{
FileReader fr =null;
try
{
fr= new FileReader("x.txt");
char[] c=new char[1024];
int ch = 0;
while((ch=fr.read(c))!=-1)//我习惯这样写
{
System.out.println(new String(c,0,ch));ch = fr.read();
}
}
catch(IOException e)
{
System.out.println(e.toString());
}
finally
{
try
{
if(fr!=null)
fr.close();
}
catch(IOException e)
{
System.out.println(e.toString());
}
}
}
}
改动后就是上面的 红色部分了,加油 |