zoukankan      html  css  js  c++  java
  • 通过Java编码获取String分行字符串的内容

    代码案列:

    import java.io.BufferedReader;
    import java.io.ByteArrayInputStream;
    import java.io.IOException;
    import java.io.InputStreamReader;
    import java.nio.charset.Charset;
    
    import net.sf.json.JSONObject;
    
    
    public class Test {
        
        public static void main(String[] args) throws IOException {
             String s="11
    22
    33
    
    abd
    ";  
             
    BufferedReader br = new BufferedReader(new InputStreamReader(new ByteArrayInputStream(s.getBytes(Charset.forName("utf8"))), Charset.forName("utf8")));    
             String line;    
             StringBuffer strbuf=new StringBuffer();  
             while ( (line = br.readLine()) != null ) {    
                 if(!line.trim().equals("")){  
                     line="<br>"+line;//每行可以做加工  
                     strbuf.append(line+"
    ");  
                 }                         
             }   
             System.out.println(strbuf.toString());  
            
          
                  
          
        }
    
    }

    结果:

    <br>11
    <br>22
    <br>33
    <br>abd

  • 相关阅读:
    Python(多进程multiprocessing模块)
    Python(队列)
    Unique Paths
    Unique Paths
    Jump Game II
    Jump Game
    Path Sum II
    Path Sum
    Remove Element
    Implement strStr()
  • 原文地址:https://www.cnblogs.com/yuanchaoyong/p/7381286.html
Copyright © 2011-2022 走看看