栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

2021-10-13—java读取ANSI格式txt文件

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

2021-10-13—java读取ANSI格式txt文件

读取ansi格式txt文件乱码了,百度找了好多都不对,最后找到了。

ansi在中国就是gb2312。

 

public List toObject(List fileList) throws Exception {
        ArrayList bizJttInfos = new ArrayList(fileList);
        for (Object bizJttInfo : bizJttInfos) {
            File file = new File(String.valueOf(bizJttInfo));
            boolean fileExists = file.exists();
            if (fileExists) {
                InputStreamReader inputStreamReader = new InputStreamReader(new FileInputStream(file),"gb2312");
                BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
                String txtJson = null;
                StringBuilder jsonStringBuffer = new StringBuilder();
                while ((txtJson = bufferedReader.readLine()) != null) {
                    String txtJson1 = txtJson.toLowerCase();
                    jsonStringBuffer.append(txtJson1);
                }
                String jsonStringBufferToString = jsonStringBuffer.toString();
                System.out.println(jsonStringBufferToString);
                BizJttInfo jsonTestDTO = JSONObject.parseObject(jsonStringBufferToString, BizJttInfo.class);
                jsonTestDTO.setFilepath(file.getPath());
                jsonTestDTO.setCreatetime(new Timestamp(System.currentTimeMillis()));
                jsonTestDTO.setSyncstate(0);
                jsonTestDTO.setSynctime(new Timestamp(System.currentTimeMillis()));
                jsonTestDTO.setDatayear("xxxx");
                List jsonTestDTOList = new ArrayList();
                jsonTestDTOList.add(jsonTestDTO);
                System.out.println(jsonTestDTOList);
                return jsonTestDTOList;
            }
        }
        return null;

 这样读取出的中文就正常了。

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/322115.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号