2018-09-12 java 读取txt

/**
* 读取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();
}

你可能感兴趣的:(2018-09-12 java 读取txt)