我正在使用getclass().getresourceasstream()方法获取属性文件。事实上,一开始我试图通过文件读取器获取文件,它工作得很好,直到我试图通过cmd运行它。我决定将读取方法设置为getresourceasstream,但它给了我以下错误:
java.io.FileNotFoundException: file:\C:\dev\tehilimwindow.jar!\images\config.properties (The filename, directory name, or volume label syntax is incorrect)
at java.base/java.io.FileInputStream.open0(Native Method)
at java.base/java.io.FileInputStream.open(FileInputStream.java:211)
at java.base/java.io.FileInputStream.<init>(FileInputStream.java:153)
at java.base/java.io.FileReader.<init>(FileReader.java:75)
at TehilimWindow.<init>(TehilimWindow.java:49)
at TehilimWindow$1.run(TehilimWindow.java:139)
at java.desktop/java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:316)
at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:770)
at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:721)
at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:715)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:391)
at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:85)
at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:740)
at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:203)
at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:124)
at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:113)
at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:109)
at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:90)
我得到一个 !
在你看到的目的地,我不知道怎么解决。
不管怎样,我想我会改变我的阅读方法fileinputstream,这是一个好的选择吗?
谢谢!
编辑:
ImageIcon icon = new ImageIcon(getClass().getResource("images//Tehilim.jpg").getFile());
我很少有其他命令尝试读取文件,但它们都是一样的^
编辑:解决-谢谢大家!我找到了解决办法。问题不是我没有使用inputstream,就是资源不在类文件夹中。
暂无答案!
目前还没有任何答案,快来回答吧!