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码表,见:
该博客介绍了如何使用C++通过FileOutputStream进行文件操作,重点讲解了第二个参数为true的写入方式,以及如何使用byte[]数组以ASCII码表写入内容,并处理可能出现的FileNotFoundException。
1177

被折叠的 条评论
为什么被折叠?



