BufferedWriter BufferedOutputStream 区别

BufferedWriter    用于读取文本文件或字符串合适:

File file = new File(directory_xml + fileName_xml);
   if (!file.exists()) {
    file.createNewFile();
   }
   OutputStreamWriter write = new OutputStreamWriter(
     new FileOutputStream(file), "UTF-8");
   BufferedWriter writer = new BufferedWriter(write);
   // 向directory_html文件夹下写入fileName_xml文件
   writer.write(cda.toString());
   writer.close();


BufferedOutputStream   读取二进制流:

 

 try  {
            	BufferedInputStream bis = new BufferedInputStream(new ByteArrayInputStream(data));
                FileOutputStream fos1 =  new  FileOutputStream ("D:\\copyjava11.pdf") ; 
                BufferedOutputStream bos1 =  new  BufferedOutputStream ( fos1,1024 ) ; 
                
                while((size=bis.read(Buffer))!=-1)
                {
                	bos1.write(Buffer,0,size);
                } 
                bos1.close () ; 
                fos1.close();
                
                
                bos1.flush();
                bis.close();
              }  catch  ( Exception e ) { 
                System.out.println ( "Exception: "  + e ) ; 
              }

你可能感兴趣的:(JAVA基础,exception,file,buffer,xml,html)