BufferedReader readLine隔行读取的大坑

logger.info(">>>>>>>>>>>>>>>>>>>>>>>>>读取txt开始");
        File file = new File(filepath);
        try {
            if (file.isFile() && file.exists()) {
                InputStreamReader read = new InputStreamReader(new FileInputStream(file), chartset);//考虑到编码格式
                BufferedReader reader = new BufferedReader(read);
                String contents = "";while ((contents = reader.readLine()) != null) {
                    contents += reader.readLine();
                    contents += "\n";
                    logger.info(contents);
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
            logger.error(e.getMessage());
        } finally {
            logger.info(">>>>>>>>>>>>>>>>>>>>>>>>>读取结束开始");
        }

 

BufferedReader readLine隔行读取的大坑

 

 

本来以为输出的时候是按照一行一行输出的,结果一次性读取了两行,看了网上大多数的解决方法,都没有什么好方法解决,就只能自己解决了。

 logger.info(">>>>>>>>>>>>>>>>>>>>>>>>>读取txt开始");
        File file = new File(filepath);
        try {
            if (file.isFile() && file.exists()) {
                InputStreamReader read = new InputStreamReader(new FileInputStream(file), chartset);//考虑到编码格式
                BufferedReader reader = new BufferedReader(read);
                String contents = "";
                String row = "";
                while ((contents = reader.readLine()) != null) {
                    contents += "\n";
                    contents += reader.readLine();
                    contents += "\n";
                    row += contents;
                }
                logger.info(row);
            }
        } catch (Exception e) {
            e.printStackTrace();
            logger.error(e.getMessage());
        } finally {
            logger.info(">>>>>>>>>>>>>>>>>>>>>>>>>读取结束开始");
        }

BufferedReader readLine隔行读取的大坑

 

 终于,暂时解决了小问题。

BufferedReader readLine隔行读取的大坑

上一篇:Photoshop制作仿手写风格的五一金色立体字


下一篇:Wget 报错 The certificate of ‘XXX’ is not trusted