package test; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; /** * @author shusheng * @description 带异常的文件写操作 * @Email shusheng@yiji.com * @date 2018/11/9 14:50 */ public class FileOutputStreamDemo4 { public static void main(String[] args) { FileOutputStream fos = null; try { fos = new FileOutputStream("fos.txt", true); fos.write(("hello").getBytes()); fos.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } finally { try { /**如果fos不是null*/ if (fos != null) { fos.close(); } } catch (IOException e) { e.printStackTrace(); } } } }