Ask Questions and Find Answers
Important:
Ask is now read-only. You can review any existing questions and answers, but not add anything new.
But - don't panic! While ask is no more, we've replaced it with discuss - the new Liferay Discussion Forum! Read more here here or just visit the site here:
discuss.liferay.com
RE: java.io.File class and absolute Path
Hi
When I create an object of java.io.File class, absolutePath of my file is wrong .
How can I solve this problem?
When I create an object of java.io.File class, absolutePath of my file is wrong .
String path = "src/main/resources/myFile.jpg";
java.io.File file = new java.io.File( path );
System.out.println( file.getAbsolutePath() );How can I solve this problem?
You cannot use a file reference because you're inside of a jar, it's not an actual file.
Instead, use getClass().getResourceAsStream() to get to the actual resource.
Instead, use getClass().getResourceAsStream() to get to the actual resource.
Thank you very much for your reply