1 import java.io.FileInputStream;
2 import java.io.IOException;
3 import java.io.ObjectInputStream;
4 import java.io.ObjectOutputStream;
5
6 public class DemoClass4IO7 {
7 public static void main(String[] args) {
8 //TODO IO 常见异常
9
10 /*
11 * 1. 异常:FileNotFoundException IOException ClassNotFoundException NotSerializableException
12 * */
13 //TODO 有可能出现异常:FileNotFoundException
14 //FileInputStream fis = new FileInputStream("");
15
16 //TODO 解决方案:按照模板这样写 try...catch...finnally
17 FileInputStream in = null;
18 ObjectInputStream ois = null;
19 ObjectOutputStream oos = null;
20
21 try{
22 in = new FileInputStream("");
23
24 //TODO 可能出现异常:IOException
25 //in.read();
26
27 //TODO 可能出现异常:ClassNotFoundException
28 //ois.readObject();
29
30 //TOOD 有可能出现异常: NotSerializableException
31 //oos.writeObject();
32
33 }catch (Exception e){
34
35 }finally {
36 //TODO 可能出现异常:IOException
37 //in.close();
38
39 //TODO 解决方案:按照模板这样写
40 try{
41 in.close();
42 }catch (Exception e){
43
44 }
45 }
46 }
47 }