@Test
public void testFileOutputStream() {
//1.创建一个File对象,表明要写入文件的位置。
//输入的物理文件可以不存在,当执行过程中,若不存在
// 会自动创建。若存在会覆盖原有的文件
File file = new File("hello2.txt");
//2.创建一个FileOutputStream的对象,将file的对象作为
//形参传递给FileOutputStream的构造器中
FileOutputStream fos = null;
try {
fos = new FileOutputStream(file);
fos.write(new String("I Love China,too!").getBytes());
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if(fos != null) {
try {
fos.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
FileOutputStream
最新推荐文章于 2022-07-19 08:45:52 发布