1.用字节读取一个文件,替换换行符,并打印
String fileName = "src/learnIO/Stream.java"; FileInputStream in = new FileInputStream(fileName); byte[] bbuf = new byte[1024]; StringBuffer sb = new StringBuffer(in.available());
int hasRead = 0; while( (hasRead = in.read(bbuf)) > 0){ sb.append(new String(bbuf,0,hasRead)); } String content = sb.toString(); content=content.replaceAll(" ", "<br>"); System.out.println("12"+content);