FileOutputStream

该博客介绍了如何使用C++通过FileOutputStream进行文件操作,重点讲解了第二个参数为true的写入方式,以及如何使用byte[]数组以ASCII码表写入内容,并处理可能出现的FileNotFoundException。
try {
			//第二个参数为true表示跟着原来的继续写
			FileOutputStream fil=new FileOutputStream("C:\\Users\\Administrator\\Pictures\\Camera Roll\\1.txt",true);
			//输出完成后一定要刷新
			byte[] b= {99,100,101,102};
			try {
				fil.write(b);
			} catch (IOException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			}
			String s="中国";
			b=s.getBytes();
			try {
				fil.write(b);
			} catch (IOException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			}
			try {
				fil.flush();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

1,第二个参数为true则跟着文件中已有的内容继续写,为false则前面的内容都不要。

2,使用byte[]数组写入时候用的是ASCII码表,见:

Ascii完整码表(256个)_东江一笑的博客-优快云博客_ascii码表

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值