Java读取String分行字符串的方法

2021-02-26 10:10:39 浏览数 (1)

参考链接: Java 字符串方法

private static void readLine(String content) throws IOException {

        BufferedReader br = new BufferedReader(new InputStreamReader(new ByteArrayInputStream(content.getBytes(Charset.forName("utf8"))), Charset.forName("utf8")));

        String line;

        StringBuffer strbuf = new StringBuffer();

        while ((line = br.readLine()) != null) {

            if (!line.trim().equals("")) {

                line = "line" line;//每行数据

                strbuf.append(line "rn");

            }

        }

        System.out.println(strbuf.toString());

    }

 }

 执行结果 

linexxxxx

linexxxxx

linexxxxx

0 人点赞