JavaFX 2 Media from file with relative path

I am trying to create a JavaFX 2 Media Instance with a relative path (in Eclipse). I tried this by writing this:

Media media= new Media("file://test.flv");

This gives me a MediaException of type MEDIA_INACCESSIBLE. The file I'm trying to download is in my root folder of the eclipse project.

I know the answer to this question How to target a file (path to it) in Java / JavaFX , but this only applies to downloading a file using an absolute path or as a resource.

thank

+3
source share
1 answer

1. , if you want to load media from a path relative to your file , you need to use resource loading. No one can be sure of their location. .java/.class

.toExternalForm(), - :

Media media= new Media(getClass().getResource("test.flv").toExternalForm());

2., workdir , :

Media media = new Media(new File("test.flv").toURI().toString());
+5

All Articles