Message Boards

java.io.File class and absolute Path

thumbnail
ali yeganeh, modified 4 Years ago.

java.io.File class and absolute Path

Regular Member Posts: 148 Join Date: 5/1/19 Recent Posts
Hi
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?
thumbnail
David H Nebinger, modified 4 Years ago.

RE: java.io.File class and absolute Path

Liferay Legend Posts: 14919 Join Date: 9/2/06 Recent Posts
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.
thumbnail
ali yeganeh, modified 4 Years ago.

RE: java.io.File class and absolute Path

Regular Member Posts: 148 Join Date: 5/1/19 Recent Posts
Thank you very much for your reply