將String保存成文件

[html] 如題,將String保存成文件。 
如題,將String保存成文件。[html] /** 
  * 將String數據存為文件 
  */ 
 public static File getFileFromBytes(String name,String path) { 
    byte[] b=name.getBytes(); 
     BufferedOutputStream stream = null; 
     File file = null; 
     try { 
         file = new File(path); 
         FileOutputStream fstream = new FileOutputStream(file); 
         stream = new BufferedOutputStream(fstream); 
         stream.write(b); 
     } catch (Exception e) { 
         e.printStackTrace(); 
     } finally { 
         if (stream != null) { 
             try { 
                 stream.close(); 
             } catch (IOException e1) { 
                 e1.printStackTrace(); 
             } 
         } 
     } 
     return file; 
 } 
   /**
     * 將String數據存為文件
     */
    public static File getFileFromBytes(String name,String path) {
     byte[] b=name.getBytes();
        BufferedOutputStream stream = null;
        File file = null;
        try {
            file = new File(path);
            FileOutputStream fstream = new FileOutputStream(file);
            stream = new BufferedOutputStream(fstream);
            stream.write(b);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (stream != null) {
                try {
                    stream.close();
                } catch (IOException e1) {
                    e1.printStackTrace();
                }
            }
        }
        return file;
    }
byte數據保存為文件:

[html] /**  
  * 將byte數據存為文件 www.aiwalls.com
  */ 
 public static File getFileFromBytes(byte[] b,String path) { 
     BufferedOutputStream stream = null; 
     File file = null; 
     try { 
         file = new File(path); 
         FileOutputStream fstream = new FileOutputStream(file); 
         stream = new BufferedOutputStream(fstream); 
         stream.write(b); 
     } catch (Exception e) { 
         e.printStackTrace(); 
     } finally { 
         if (stream != null) { 
             try { 
                 stream.close(); 
             } catch (IOException e1) { 
                 e1.printStackTrace(); 
             } 
         } 
     } 
     return file; 
 } 

 

摘自 agods–足跡

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *