奇怪的Java运行时错误 - currency.data

14

在运行时我一直收到这个错误,但我不知道是什么原因造成的。它认为有一个文件丢失了吗?

Caused by: java.io.FileNotFoundException: C:\Program Files\Java\jdk1.7.0_07\lib\currency.data

currency.data是什么,有人能建议一下为什么会发生这种情况吗?我的JDK也不算太旧,因为我们现在已经更新到7u17了。

Exception in thread "AWT-EventQueue-0" java.lang.InternalError
    at java.util.Currency$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.util.Currency.<clinit>(Unknown Source)
    at java.text.DecimalFormatSymbols.initialize(Unknown Source)
    at java.text.DecimalFormatSymbols.<init>(Unknown Source)
    at java.text.DecimalFormatSymbols.getInstance(Unknown Source)
    at java.text.NumberFormat.getInstance(Unknown Source)
    at java.text.NumberFormat.getNumberInstance(Unknown Source)
    at java.util.Scanner.useLocale(Unknown Source)
    at java.util.Scanner.<init>(Unknown Source)
    at java.util.Scanner.<init>(Unknown Source)
    at ciphor.CiCompile$7.actionPerformed(CiCompile.java:458)
    at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
    at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
    at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
    at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
    at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
    at java.awt.Component.processMouseEvent(Unknown Source)
    at javax.swing.JComponent.processMouseEvent(Unknown Source)
    at java.awt.Component.processEvent(Unknown Source)
    at java.awt.Container.processEvent(Unknown Source)
    at java.awt.Component.dispatchEventImpl(Unknown Source)
    at java.awt.Container.dispatchEventImpl(Unknown Source)
    at java.awt.Component.dispatchEvent(Unknown Source)
    at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
    at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
    at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
    at java.awt.Container.dispatchEventImpl(Unknown Source)
    at java.awt.Window.dispatchEventImpl(Unknown Source)
    at java.awt.Component.dispatchEvent(Unknown Source)
    at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
    at java.awt.EventQueue.access$200(Unknown Source)
    at java.awt.EventQueue$3.run(Unknown Source)
    at java.awt.EventQueue$3.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
    at java.awt.EventQueue$4.run(Unknown Source)
    at java.awt.EventQueue$4.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
    at java.awt.EventQueue.dispatchEvent(Unknown Source)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.run(Unknown Source)
Caused by: java.io.FileNotFoundException: C:\Program Files\Java\jdk1.7.0_07\lib\currency.data (The system cannot find the file specified)
    at java.io.FileInputStream.open(Native Method)
    at java.io.FileInputStream.<init>(Unknown Source)
    at java.io.FileInputStream.<init>(Unknown Source)
    ... 48 more

我正在JDK环境下运行我的程序,我检查了我的jre7文件夹,currency.data在那里出现了!为什么它只存在于jre文件夹中?


也许值得卸载/重新安装您的JDK/JRE? - assylias
@assylias 我将升级我的JDK到最新版本,看看那个文件是否神奇地出现了。 - Ciphor
我认为它应该在rt.jar文件中... - assylias
@assylias 好吧,在 C:\Program Files\Java\jre7\lib 中它就漂浮在那里。 - Ciphor
7个回答

14

我曾经遇到过类似的错误,现在我分享一下,希望能够帮助其他可能会掉入同样困境的人 :)

错误信息 :

java.lang.InternalError: java.io.FileNotFoundException: null/lib/currency.data (No such file or directory)

这是因为我设置了全局属性,结果证明这是一件非常不聪明的事情。

System.setProperties(new Properties());

系统属性包含非常重要的数据,包括:

  • path.separator
  • user.dir
  • file.encoding
  • file.separator
  • java.io.tmpdir

所以,除非你知道自己在做什么,否则不要进行以上操作。

如果你想添加一个属性,请使用以下方法:

System.getProperties().put("SOME_KEY", "SOME_VALUE");
或者
Map myCustomMapOfProps = ...
System.getProperties().putAll(myCustomMapOfProps);

哈哈哈,我在嘲笑我刚刚做的 System.setProperty(new Properties()); :D - Anand Rockzz
Java 没有提供一种不覆盖现有属性的方式来添加属性,这真是太愚蠢了。 - Sridhar Sarnobat
@Sridhar-Sarnobat,实际上你可以这样做。我已经更新了我的答案 :) - rjdkolb
1
@Sridhar-Sarnobat,我可能误解了你的意思,但为什么不将属性文件读入映射中并执行putAll操作。已添加到我的答案中。 - rjdkolb
1
...而且Properties实现了我没有预料到的java.util.Map接口。所以这很好,也很容易。 - Sridhar Sarnobat
显示剩余3条评论

5
这是我的解决方案。 你可以将它添加到你的代码中:
System.setProperty("java.home", "C:\\Program Files\\Java\\jdk1.8.0_60\\jre");

您需要替换为您所使用的jdk版本的路径。


1
是的,这也是我的解决方案!在jdk1.8.0_60\lib文件夹中没有“tzdb.dat”。 - Kartik Chugh

3

我曾遇到同样的问题。这是由于Java版本冲突引起的(“JAVA_HOME”被设置为1.7,而属性“-Djava.home”被设置为1.6)。

我在使用mvn构建项目时,在环境变量MAVEN_OPTS中,选项“java-home”被设置为错误的值:

MAVEN_OPTS = -Xmx512m -XX:MaxPermSize=256m "-Djava.home=C:\Program Files\Java\jdk1.6.0_35\jre"

将其修正为:

MAVEN_OPTS = -Xmx512m -XX:MaxPermSize=256m

还需检查您的其他环境变量:

MAVEN_OPTS
JAVA_HOME

1
我发现currency.data可以在以下任一目录中找到:

C:\Program Files\Java\jdk1.7.0_17\jre\lib

或者

C:\Program Files\Java\jdk1.7.0_07\lib

出于某种原因,当我执行程序时,Java不知道要再深入查找一个目录。

它位于文件夹 C:\Program Files\Java\jdk1.7.0_17\jre\lib 下,而不是 C:\Program Files\Java\jdk1.7.0_07\lib。好的,谢谢,这很有帮助。 - Chirag

0
JDK 1.7.0_43在lib/下没有currency.data,只有在jre/lib下才有。这迫使我更改构建脚本以使用JDK进行编译,然后使用JRE进行单元测试。除非有更好的方法。

0
在早期,Sun 公司规定如果安装的是 JDK 而不是 JRE,则 JAVA_HOME 应该指向 JDK_HOME/jre。
由于普及程度的原因,这种区分已经逐渐消失,就像“exalator”成为“escalator”的可接受发音一样。
无论如何,一些老的应用程序仍然假定 JAVA_HOME 是 JRE 的根目录。

0

我在Wildfly 10中部署的Web应用程序中遇到了同样的问题,这是在安装新的JRE时服务器正在运行。重新启动服务器解决了这个问题。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接