我的项目结构是这样的
--源
我多次使用此子文件夹,如下所示:
File tempFile = new File("src/saves/" + videoName + ".json");
或者有时像这样:
ImageView icon = new ImageView("resources/edit.png");
和:
File f = new File("src/resources/zelda.mp4");
由于某些原因,它适用于icon
,但不适用于视频/文件,当我尝试时,我得到了这个错误:
Caused by: MediaException: MEDIA_UNAVAILABLE : C:\Users\histackoverflow\IdeaProjects\project2\resources\zelda.mp4 (specified path can't be found)
所以我想知道我使用path的方式出了什么问题?
发布于 2019-05-20 01:10:57
@Edit:这适用于在IDE中引用文件。对于jar中的适当文件引用,请遵循以下内容:Java Jar file: use resource errors: URI is not hierarchical
我不建议以字符串的形式输入路径。加载文件的一种更好的方法是将它们放到资源中(您已经这样做了),并通过类引用调用资源并从中获取URI:
InputStream file = new FileInputStream(getClass().getResource("/edit.png").getPath());
Image image = new Image(file);
ImageView icon = new ImageView(image);
File f = new File(getClass().getResource("/zelda.mp4").toURI());
确保包含资源的目录被标记为资源目录。
https://stackoverflow.com/questions/56210139
复制相似问题