13OutputStream

来源:互联网 发布:BOM是哪个软件 编辑:程序博客网 时间:2024/05/20 03:08
对字节的操作,任意格式文件。
字节流:其实字符流底层还是对字节的操作
InputStram 读数据
OutputStram 写数据


package test.io;


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


/**
 * [说明/描述]
 * 
 * @author CaiHaiming
 * @date 2016-7-24 下午5:12:17
 * @company chm
 * @version 1.0
 * @copyright copyright (c) 2016
 */
public class FileOutputStreamDemo1 {
public static void main(String[] args) {
FileOutputStream fos = null;
try {
fos = new FileOutputStream("file1.txt");
String line = "asdsfbkjs中文测试dfd74";// 中文是可以输入的
fos.write(line.getBytes());// 仅支持byte数组,可以使用str.getBytes()
fos.flush();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
if (fos != null) {
try {
fos.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
}
0 0
原创粉丝点击