package com.chj.io;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
/**
* 字节文件输出流
* @author Administrator
*
*/
public class IOTest04 {
public static void main(String[] args) {
File dest=new File("dest.txt");//文件不存在则可以创建
OutputStream os=null;
try {
os=new FileOutputStream(dest,false);//为false则是覆盖写入,为true则是追加写入
String msg="chai hong jun tong xue zheng zai nu li xue xi java";
byte[] datas=msg.getBytes();
os.write(datas, 0, datas.length);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally {
if(null!=os) {
try {
os.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
}
【JAVA】IO之文件字节输出流
最新推荐文章于 2023-05-19 09:04:34 发布