代码改变世界

Java IO 写文件

2016-11-22 11:22  甘雨路  阅读(185)  评论(0编辑  收藏  举报
package com.lf.fileproject;

import java.io.File;
import java.io.FileOutputStream;

import org.junit.Test;

public class Test2 {
    @Test
    public void  test2() {
        File file = new File("d:/aSong.txt");
        FileOutputStream outputStream = null;
        try {
            outputStream = new FileOutputStream(file);
            outputStream.write(new String("codes life").getBytes());
            if (outputStream!=null) {
                outputStream.close();
            }
        } catch (Exception e) {
            // TODO: handle exception
        }
        
        
    }
}