FileOutputStream类的使用

来源:互联网 发布:淘宝模块装修教程 编辑:程序博客网 时间:2024/06/15 07:02

使用示例

package cn.itcast_01;import java.io.File;import java.io.FileNotFoundException;import java.io.FileOutputStream;import java.io.IOException;public class FileOutputStreamDemo {    public static void main(String[] args) throws IOException {        String path = "...../test.txt";        FileOutputStream out = new FileOutputStream(path, true);        //第二个参数设为true表示写入时在文件末尾写,不覆盖文件原本内容,若不加此参数则为覆写        OutputStreamWriter osw = new OutputStreamWriter(out, "UTF-8");        //第二个参数为设定编码格式        osw.write("要写入的内容");        osw.close();        out.close();    }}
原创粉丝点击