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);

 

posted @ 2016-10-27 11:50  lakeslove  阅读(124)  评论(0编辑  收藏  举报