代码案列:
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