@Test
//使用read的重载方法
public void TestFileRead1() throws IOException {
FileReader fr = null;
try {
//1:File的实例化
File file = new File("C:\\Users\\86152\\Desktop\\垃圾\\Test.txt");
//2:FireReader的实例化
fr = new FileReader(file);
//3:读入的操作
// read(char[] cbuf)--> 返回每次读入cbuf数组中的字符的个数
//如果到末尾 返回-1
char[] cbuf = new char[5];
int len;
while ((len = fr.read(cbuf)) != -1){
for (int i = 0;i < len;i++){
System.out.print(cbuf[i]);
}
}
} catch (IOException e) {
e.printStackTrace();
} finally {
fr.close(); //4:资源的关闭
}
}
数据的读入操作(FireWrite)Read的重载方法
最新推荐文章于 2024-07-29 18:00:00 发布