我有一个崩溃的服务器(如果你想知道我的世界),一些宝贵的数据被保存在一个序列化的目标文件中。我没有成功用 Java 的 ObjectInputStream 读取它。这是我在网上找到的一段代码,稍微编辑了一下。当我读取对象时,它会引发 ClassNotFoundException。
//Part of it
ObjectInputStream objStream = new ObjectInputStream(new FileInputStream(f));
Object obj = objStream.readObject();
System.out.println("The Object : "+ obj);
objStream.close();
System.out.println("Deserializing Operation Completly Successfully.");
问题是我根本不知道它的内容。我如何知道该对象中包含哪些字段和方法?
java.lang.ClassNotFoundException: net.****.****.****.**** //CENSORED
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:249)
at java.io.ObjectInputStream.resolveClass(ObjectInputStream.java:602)
at java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:1589)
at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1494)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1748)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1327)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:349)
at java.util.ArrayList.readObject(ArrayList.java:593)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at java.io.ObjectStreamClass.invokeReadObject(ObjectStreamClass.java:979)
at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1871)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1775)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1327)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:349)
at main.ReadFile.main(ReadFile.java:28)
编辑:我已经反编译了它,并将它的所有包添加到我的 src 中。成功读取对象。但这并不能回答问题,问题仍然存在;“如何在 Java 中读取未知的序列化对象。”。