package com.bdqn.lession2;
import java.io.File;
import java.io.IOException;
public class FileOutputStream {
public static void main(String[] args) {
File file = new File("c:\\android11472.txt");
if (!file.exists()) {
try {
file.createNewFile();
} catch (IOException e) {
// TODO 自动生成的 catch 块
e.printStackTrace();
}
System.out.println("文件夹创建成功");
} else {
System.out.println("文件夹创建失败");
file.delete();
}
FileOutputStream fos =null;
try {
fos = new FileOutputStream(file);
fos.write("hello wrold".getBytes());
fos.write('a');
fos.flush();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}finally{
if(fos != null){
try {
fos.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
}
FileOutputStream fos =null;
try {
fos = new FileOutputStream(file);
fos.write("hello wrold".getBytes());
这段后面就开始画红线了 不知道为什么