I have the following source code snippet
import java.net.URI;
import java.net.URISyntaxException;
File file = new File("pic.png");
BufferedImage image = ImageIO.read(file);
String string = "pic.png";
URI path = new URI(string);
File f = new File(path);
ColorProcessor image = new ColorProcessor(ImageIO.read(f));
Thus, the path that the file receives is correct. The image is buffered correctly. Now my problem is that I get the following exception
Exception in thread "main" java.lang.IllegalArgumentException: URI is not absolute
at java.io.File.<init>(Unknown Source)
Why is my path not absolute? And how am I doing it right?
If I change the path as follows:
String string = "C:'\'Users'\'Jurgen'\'newFile'\'myProject'\'pic.png";
And I tried like this
String string = "C:/Users/Jurgen/newFile/myProject/pic.png";
Then i get a new exception
Exception in thread "main" java.lang.IllegalArgumentException: URI is not hierarchical
at java.io.File.<init>(Unknown Source)
PS does not work with android packages for uri
Thanks in advance =)
source
share