将序列化后的对象写入文件后,可以从文件中读取并反序列化该对象,也就是说,可以利用表示对象及其数据类型信息和字节来在内存中重新创建该对象。示例 import java.io.*; public class DeserializeDemo { public static void main(String [] args) { Employee e = null; try { FileInputStream fileIn = new FileInputStream("/tmp/employee.ser"); ObjectInputStream in = new ObjectInputStream(fileIn); e = (Employee) in.readObject(); in.close(); ... 阅读更多
throw 关键字用于显式引发异常。示例 public class Test { public static void main(String[] args) { throw new NullPointerException(); } } Exception in thread "main" java.lang.NullPointerException at a6.dateAndTime.Test.main(Test.java:5) throws 关键字在 Java 中用于推迟已检查异常的处理。public class Test { public static void main(String[] args)throws NullPointerException { throw new NullPointerException(); } }