1. Scenario: The String string contains branches, and each line needs to be extracted and processed.
2. The reference code is as follows:
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="<br>"+line;//Each line can be processed strbuf.append(line+"/r/n"); } } System.out.println(strbuf.toString()); }Execution results:
<br>1<br>2<br>3<br>abd
The above method of reading String branch strings in Java is all the content I share with you. I hope you can give you a reference and I hope you can support Wulin.com more.