Java追加文件的三种方式

  1. import java.io.BufferedWriter;  
  2. import java.io.File;  
  3. import java.io.FileOutputStream;  
  4.   
  5.             randomFile.seek(fileLength);     
  6.             randomFile.writeBytes(content);      
  7.         } catch (IOException e) {     
  8.             e.printStackTrace();     
  9.         } finally{  
  10.             if(randomFile != null){  
  11.                 try {  
  12.                     randomFile.close();  
  13.                 } catch (IOException e) {  
  14.                     e.printStackTrace();  
  15.                 }  
  16.             }  
  17.         }  
  18.     }    
  19.   
  20.     public static void main(String[] args) {  
  21.         try{  
  22.             File file = new File("d://text.txt");  
  23.             if(file.createNewFile()){  
  24.                 System.out.println("Create file successed");  
  25.             }  
  26.             method1("d://text.txt", "123");  
  27.             method2("d://text.txt", "123");  
  28.             method3("d://text.txt", "123");  
  29.         }catch(Exception e){  
  30.             System.out.println(e);  
  31.         }  
  32.     }  
  33.  
 
posted on 2017-02-14 10:44  sdfczyx  阅读(169)  评论(0)    收藏  举报