System.out.print(new String(buf,0,num));import java.io.*;
class FileReaderDemo
{
public static void main(String[] args) throws Exception
{
FileReader fr = new FileReader("C:\\yixia.log");//创建一个文件读取流,先跟文件关联起来,要保证该文件是存在的,如果不存在,会抛出异常,这个异常是FileNotFoundException
/* int ch = 0;
while (ch != -1)
{
ch = fr.read();
System.out.println((char)ch);
}
*/
char[] buf = new char[1024];
int num = 0;
while((num = fr.read(buf)) != -1)
{
//System.out.print(new String(buf,0,num));
System.out.print(buf);//如果文档过大,超过1024字节,为什么只能打印1024字节。而被我注释掉的代码绿色为什么就正常那
}
}
} |
|