-
Notifications
You must be signed in to change notification settings - Fork 170
Open
Description
Reading the File works when app is executed from the IDE, but if you compile and execute:
javac Main.java
java Main
then it throws:
Exception in thread "main" java.lang.IllegalArgumentException: File: app.log not found.
at ResourceHelper.getAbsoluteFilePath(ResourceHelper.java:11)
at Main.main(Main.java:15)
ResourceHelper.java:
public class ResourceHelper {
public static String getAbsoluteFilePath(String filename) {
URL resource = ClassLoader.getSystemClassLoader().getResource(filename);
if (resource == null) {
throw new IllegalArgumentException("File: " + filename + " not found.");
}
try {
Path path = Paths.get(resource.toURI());
return path.toString();
} catch (URISyntaxException e) {
throw new IllegalArgumentException(e.getMessage());
}
}
}
Any suggestion to solve this?
Metadata
Metadata
Assignees
Labels
No labels