package collection;
import java.io.*;
import java.util.*;
public class Demo1 {
/**
* @param args
* @throws IOException
* @throws IOException
*/
public static void main(String[] args) throws IOException {
FileReader fr = new FileReader("F:\\demo.txt");
char[] buf = new char[1024];
int num = 0;
while((num = fr.read(buf))!=-1){
sop(new String(buf,0,num));
}
}
private static void sop(Object string) {
System.out.println(string);
}
}
本文提供了一个使用Java进行文件读取的简单示例。通过FileReader类和字符缓冲区,该示例演示了如何逐字符读取文本文件并将其内容输出到控制台。

被折叠的 条评论
为什么被折叠?



