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

你可能感兴趣的:(BufferedWriter 写入字符流及换行问题)