2018-09-12 java 读取txt
2018-09-14 本文已影响27人
Mylovesunshine
/**
* 读取txt文件
*
* @param file
* @return
*/
public static String readTxtFile(File file) {
StringBuilder result = new StringBuilder();
try {
//中文乱码问题
BufferedReader br = new BufferedReader(new InputStreamReader(new
FileInputStream(file), "gbk"));
// BufferedReader br = new BufferedReader(new FileReader(file));
String temp = null;
while ((temp = br.readLine()) != null) {
result.append(temp);
}
br.close();
Log.i("ss", result.toString());
} catch (Exception e) {
e.printStackTrace();
}
return result.toString();
}