Reputation: 519
I am getting this error:
Caused by: java.net.URISyntaxException: Illegal character in opaque part at index 2: C:\Users\Emre\Desktop\PN1g1z.gif
And I really don't get what's wrong.
This is what throws the exception:
Media media = new Media(file.getAbsolutePath());
Upvotes: 2
Views: 13043
Reputation: 79
I had a similar problem but another exception: java.lang.IllegalArgumentException: Illegal character in opaque part at index 2: C:\Users\MyUser\project\src\main\packagex\file.csv
The project was created using java not by me. It tried to read a csv file. It worked ok on linux but crashed on windows 10.
My solution was change the absolute path to relative and switch reverse slash to "normal" slash. The url finally worked with this:
src/main/packagex/file.csv
It seems colon and reverse slash triggered the exception. That is the reason exception indicates index 2 because colon is located in second position at url
Illegal character in opaque part at index 2: C:\Users\MyUser...
Upvotes: 0
Reputation: 470
Actually, it's a big problem where you put your server.
I already faced this problem before. I used Geronimo with the space in my direction D:\Common DevTool\Geronimo
.
You have two ways to resolve:
D:\Tool\Geronimo
. It ran well.
Your directory is not correct: C:/Program Files
. You should move your server to another place without the space in the name.Upvotes: 0
Reputation: 14061
Media
expects an URI as String in the constructor. So, instead of using File#getAbsolutePath()
, you should be using File#toURI()
instead.
https://docs.oracle.com/javase/7/docs/api/java/io/File.html#toURI%28%29
From the Media#new
JavaDoc (thanks @Andreas):
source - The URI of the source media.
Upvotes: 9