从文件读取文本,避免中文乱码
2016-08-25 17:04
363 查看
private static String readFile(String filePath) {
File file = new File(filePath);
String content = "";
StringBuilder sb = new StringBuilder();
try {
BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(file), "GBK"));
while (content != null) {
content = br.readLine();
if (content == null) {
break;
}
sb.append(content.trim());
}
br.close();
}
catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return sb.toString();
}
File file = new File(filePath);
String content = "";
StringBuilder sb = new StringBuilder();
try {
BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(file), "GBK"));
while (content != null) {
content = br.readLine();
if (content == null) {
break;
}
sb.append(content.trim());
}
br.close();
}
catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return sb.toString();
}
相关文章推荐
- VC 读取文本文件内容,中文乱码的问题解决
- JAVA读取文件,避免中文乱码。
- JAVA读取文件,避免中文乱码
- 使用guava读取ANSI类型的文件,避免中文乱码
- 读取,分割,分页读取UTF-8文件时,避免中文乱码
- 文本文件中读取中文乱码的问题
- JAVA读取文件,避免中文乱码
- JAVA读取文件,避免中文乱码
- C#正确读取中文文件,避免乱码
- ResourceBundle (读取properties文件及中文乱码解决方法)
- JAVA读写文件如何避免中文乱码
- Java读取properties文件中文乱码问题的解决
- 【转载】C#中StreamReader读取中文文本出现乱码的解决方法
- 解决在linux下用eclipse打开windows文本文件产生中文乱码的问题
- Andoird - 解决读取txt文件中文乱码问题
- C#中StreamReader读取中文文本出现乱码的解决方法
- C#中StreamReader读取中文文本出现乱码的解决方法(转)
- 读取资源文件,中文乱码怎么解决,转换为ASCII码
- Java读取文件 解决中文乱码问题
- 读取本地UTF-8文件带有换行的中文文本