博客首页 注册 建议与交流 排行榜 加入友情链接
推荐 投诉 搜索: 帮助

program-life

所有的一切都要靠我自的努力去获得,这样我才能抬起头来做人...... 别人的永远不会是我的......
myprogramlife.cublog.cn


读取文件内容的方法
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);

发表于: 2008-04-02 ,修改于: 2008-04-02 16:12,已浏览129次,有评论0条 推荐 投诉


网友评论

发表评论