If i have a project which has a text file inside of it and i want to be able to read this text file which will be stored in my runnable jar then how can i do this? Currently i have a setup like this
public void someMethod()
{
File f = new File("aFileInEclipseResourcesFolder.txt");
doSomethingWithFile(f);
}
private void doSomethingWithFile(File f)
{
//print the data in the file;
}
The issue is the application cant locate the file if i use this approach but if i use a hard coded path to the file then it works. I know you can use getClass().getResourceAsStream() but this wont allow me to get the already written file in to a file object without rewriting it again, or is this assumption incorrect?
Regards
You don’t want to use getResourceAsStream() you want
the URL will give you the path to the resource and you can create a File object from that.