package ioDemo;
import java.io.FileReader;
import java.io.IOException;
import java.util.Arrays;
public class FileReadDemo {
public static void main(String[] args)throws IOException {
FileReader fr = new FileReader("demo.txt");
/*while(true){
int num = fr.read();
if(num ==-1)
break;
System.out.println((char)num);
}
int num;
while((num = fr.read())!=-1){
System.out.println((char)num);
}
fr.close();
*/
/*char[] buf = new char[3];
int num = fr.read(buf);
System.out.println(num+"***"+new String(buf));
char[] buf2 = new char[3];
int num2 = fr.read(buf2);
System.out.println(num2+"***"+new String(buf2));
char[] buf3 = new char[3];
int num3 = fr.read(buf3);
System.out.println(num3+"***"+new String(buf3));
*/
char[] buf = new char[1024];
int num;
while((num=fr.read(buf))!=-1){
System.out.println(new String(buf,0,num));
}
fr.close();
}
}
|
|