首页 > 代码库 > IO例子

IO例子

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("\r\n", "<br>"); System.out.println("12"+content);

 

IO例子