java读取分行字符串

java读取分行字符串_第1张图片 

public static void main(String[] args) throws IOException{
		 String s="1\r\n2\r\n3\r\n \r\nabd\r\n";
		 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="
"+line;//每行可以做加工 strbuf.append(line+"\r\n"); } } System.out.println(strbuf.toString()); }

执行结果:

 

 


1
2
3
abd

你可能感兴趣的:(java)