This content has been marked as final. Show 5 replies
As for my knowledge "." will fetch from the directory where we are running.Exactly. A directory. Not a JAR file. If you want to access it via File, you can't put it into the JAR. if you want to put it into the JAR, you need to use Class.getResource() and friends.
Iam using the following Code.
String path = getClass().getClassLoader().getResource("fileList.txt").getPath();
This is printing the path, but while running in the eclipse its throwing "FileNotFound Exception", even the file exists
You're going about it the wrong way. The file is IN the jar right? Then its not on the actual filesystem, so you're not going to be using File/IO classes to access it.
In stead, use getClass().getClassLoader().getResourceAsStream() to directly get an inputstream to the file to be able to load it.
That works fine.
Iam able to get the resource file path using getResourceAsStream.
How can i get the folder path in the jar???
Thanks in advance
I've answered that. getResource(). It gives you a URL, or null. But it isn't a path you can treat as though it could be fed to a File, as everybody has already told you.