String path = “D:\test.txt”; //此处的path包括文件名
String str = “”;
String content = “”;
BufferedReader in = new BufferedReader(new FileReader(path));
while(str = in.readline() != null){
content = content + str;
}
in.close();
System.out.println(content);
如果文件内容为中文,读取文件内容的方法为:
String str = “”;
String content = “”;
String path = “D:\test.txt”;
File f = new File(f);
InputStreamReader is = new InputStreamReader(new FileInputStream(f),”UTF-8”);
BufferedRead in = new BufferedRead(is);
while(str = in.readline() != null){
content = content + str;
}
in.close();
System.out.println(content);
阅读(1358) | 评论(1) | 转发(0) |