首页 > 其他 > 详细

字节输出流

时间:2019-10-27 16:44:16      阅读:75      评论:0      收藏:0      [点我收藏+]

package com.study02;

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

/**
* 文件字节输出流
* 1.创建源
* 2.选择流
* 3.操作(写出内容)
* 4.释放资源
* @author Administrator
*
*/

public class IOtest04 {
public static void main(String[] args) {
File src = new File("aaa.txt");
OutputStream os = null;
try {
os = new FileOutputStream(src,true);//true:在原来的基础上写入;false:清空原来的数据,重新写入

String msg = new String("IO is so easy!");
byte[] datas = msg.getBytes();//字符串-->字节数组(编码)
os.write(datas,0,datas.length);
os.flush();

} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}finally {
if (os!=null) {
try {
os.close();
} catch (IOException e) {
e.printStackTrace();
}
}

}
}
}

字节输出流

原文:https://www.cnblogs.com/LuJunlong/p/11747765.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!