我正在构建一个可以播放视频的小应用程序,问题是,当我在其路径中添加带有空格的视频时 - 它会给我一个错误:
java.net.URISyntaxException: Illegal character in opaque part at index 13: FILE:C:/Video menu/video/03.mp4
Run Code Online (Sandbox Code Playgroud)
这是我的场景:
Group root = new Group();
Scene scene = new Scene(root, 1280, 1024, Color.BLACK);
String path = new String("FILE:C:/Video menu/touchMV/03.mp4");
URI uri = new URI(path);
root.getChildren().add(
MediaViewBuilder.create()
.mediaPlayer(
MediaPlayerBuilder.create()
.media(
new Media(
path
)
).build()
).build()
);
stage.setScene(scene);
stage.show();
Run Code Online (Sandbox Code Playgroud)
该Media(java.lang.String source)文件说,它有限制:
我试图传递一个Media()构造函数(new URI(path)).toString();,(new URI(path)).toASCIIString()但它没有用.将空格更改为%20不起作用.
在这种情况下我该怎么办?
我不知道你的问题的原因,但是如果你创建了File第一个并且调用它就可以了File#toURI#toASCIIString.
File file = new File("C:\\Video menu\\touchMV\\03.mp4");
String path = file.toURI().toASCIIString();
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2104 次 |
| 最近记录: |