BufferedWriter 写入字符流及换行问题

      public  boolean  write(File file,String webContent){
          
          //目录测试
         boolean isok=false;
        File parentFile=  file.getParentFile();
        if(parentFile.exists()==false){
            parentFile.mkdirs();
        }
          
         try {
             
             FileOutputStream fo=new FileOutputStream(file);
             
             //utf-8
             
             java.io.OutputStreamWriter or=new  java.io.OutputStreamWriter(fo,this.getFileEncode());
             
             java.io.BufferedWriter bo=new   java.io.BufferedWriter (or);
             
             //通过字符流读取Html文档,解决换行问题
            java.io.StringReader ir=new java.io.StringReader(webContent);
            
               java.io.BufferedReader br=new java.io.BufferedReader(ir);
               
              String brString= br.readLine();
              while(brString!=null){
                      bo.write(brString);
                      //增加换行
                      
                      bo.newLine();
                      
                       brString= br.readLine();
              }
            
         
             
             bo.flush();
             
             //
             bo.close();
             
             or.close();
             
             fo.close();
             
             
                isok=true;
             
         } catch (FileNotFoundException ex) {
             
             isok=false;
             Logger.getLogger(LocFileBIOService.class.getName()).log(Level.SEVERE, null, ex);
         } catch (IOException ex) {
                isok=false;
             Logger.getLogger(LocFileBIOService.class.getName()).log(Level.SEVERE, null, ex);
         }
         
         
         return isok;  
    }
阅读更多
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭