【发布时间】:2014-04-30 05:58:34
【问题描述】:
当我的程序进入关闭挂钩并尝试将设置文件写入文本文档时,会出现此错误。奇怪的是,它不会每次都抛出异常。
Exception in thread "Thread-4" java.lang.IllegalStateException: zip file closed
at java.util.zip.ZipFile.ensureOpen(Unknown Source)
at java.util.zip.ZipFile.getEntry(Unknown Source)
at java.util.jar.JarFile.getEntry(Unknown Source)
at java.util.jar.JarFile.getJarEntry(Unknown Source)
at com.crimson.server.JarClassLoader.findJarEntry(JarClassLoader.java:514)
at com.crimson.server.JarClassLoader.findJarClass(JarClassLoader.java:584)
at com.crimson.server.JarClassLoader.loadClass(JarClassLoader.java:956)
at java.lang.ClassLoader.loadClass(Unknown Source)
at com.crimson.universalUtils.Datastore.store(Datastore.java:66)
at com.crimson.server.ServerShutdownHook.run(ServerShutdownHook.java:38)
这里是 Datastore.store(设置):
public static File set = new File("settings.properties");
public static void store(Settings settings){
set.delete();
try {
set.createNewFile();
PrintWriter pw = new PrintWriter(set);//line 66
pw.println(ObjectTransfer.toString(settings));
pw.close();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
我不知道为什么创建 PrintWriter 会调用 ClassLoader.loadClass,但这可能是问题所在,因为我正在使用 JarClassLoader:http://www.jdotsoft.com/JarClassLoader.php
【问题讨论】:
-
代码是否被多个线程调用?
标签: java jar classloader