您的位置:首页 > 其它

从文件读取文本,避免中文乱码

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();

    }
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: