public class IOException {
public static void main(String[] args) {
// 1.建立输出流对象
// 2.处理异常
FileOutputStream fos = null;
try {
File file = new File("e:d.txt");
fos = new FileOutputStream(file);
fos.write("dsdsd".getBytes());
} catch (Exception e) {
System.out.println(e.toString());
throw new RuntimeException("文件写入失败,请重试");
} finally {
try {
if (fos != null)
fos.close();
} catch (Exception e) {
throw new RuntimeException("关闭资源失败");
}
}
}
}