s-day09--字符流一次读取一个字符数组
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
package com.inmind.reader03;
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
|
||||
//请大家一次读取一个字符数组的内容,读取srouce2.txt
|
||||
//int read(char[] cbuf) 将字符读入数组。
|
||||
public class Demo11 {
|
||||
public static void main(String[] args) throws IOException {
|
||||
FileReader fr = new FileReader("source2.txt");
|
||||
char[] chars = new char[1024];
|
||||
//int len = fr.read(chars);
|
||||
int len;
|
||||
while ((len = fr.read(chars))!= -1){
|
||||
System.out.println(new String(chars,0,len));
|
||||
}
|
||||
fr.close();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user