`

文本内容保存为一个文件FileOutputStream

阅读更多

给自己记录下,方便以后自己再去查找

import java.io.File;
import java.io.IOException;
import java.io.BufferedOutputStream;
import java.io.FileOutputStream;
public class ccc {
    public static void main(String[] args) {
        FileOutputStream fos = null;
        BufferedOutputStream bos = null;
        try {
            String aa = "hahahah";
            File file = new File("c:/bulletin2.txt");
            if (!file.exists()) {
                file.createNewFile();
            }
            fos = new FileOutputStream(file);
            bos = new BufferedOutputStream(fos);
            bos.write(aa.getBytes());
            bos.flush();
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            try {
                bos.close();
                fos.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics