1. 程式人生 > >android-解決讀取txt檔案中文亂碼問題

android-解決讀取txt檔案中文亂碼問題

參考連結:http://blog.csdn.net/dengta_snowwhite/article/details/6418384

方法:

public static String readFile(String filePath) {
        StringBuilder sb = new StringBuilder();
        try {
            BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(filePath), "GB2312"));
            String line = null;
            while ((line = reader.readLine()) != null) {
                sb.append(EncodingUtils.getString(line.getBytes("utf-8"), "utf-8"));
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return sb.toString();
    }