您的位置:首页 > 编程语言 > PHP开发

IO流——文件操作流之字节输出流FileOutputStream

2016-08-15 11:01 357 查看
package com.qianfeng.demo04;

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) {
FileOutputStream fos = null;

try {
//1.创建一个文件输出字节流对象
fos = new FileOutputStream(new File("c:/aa.txt"),true);
//2.准备数据源,并且将数据源转化为字节数组。
String str = "温柔可爱美丽大方和善端庄有智慧";
//3.将字节数组写入到输出流当中。
fos.write(str.getBytes());
//4.刷新输出流
fos.flush();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}finally {
if (fos!=null) {
try {
//5.关闭流
fos.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}

}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  io流
相关文章推荐