字符串寫入文件 – JAVA編程語言程序開發技術文章

package com.zhangry.interview.java; 
 
import java.io.FileNotFoundException; 
import java.io.FileOutputStream; 
import java.io.IOException; 
 
public class WriteFile { 
 
    public static void main(String[] args) { 
        try { 
            FileOutputStream out = new FileOutputStream("C:\\FileName.txt"); 
            out.write("字符串寫入文件".getBytes()); 
            out.close(); 
        } catch (FileNotFoundException e) { 
            e.printStackTrace(); 
        } catch (IOException e) { 
            e.printStackTrace(); 
        } 
 
    } 
 

package com.zhangry.interview.java;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

public class WriteFile {

    public static void main(String[] args) {
        try {
            FileOutputStream out = new FileOutputStream("C:\\FileName.txt");
            out.write("字符串寫入文件".getBytes());
            out.close();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }

    }

}

 

摘自  張仁陽專欄 

發佈留言