0

I have a program that needs to use a .txt file in it. I have used the following code successfully to run the program right from eclipse:

File configFile = new File("src/config.txt");

With the file obviuosly residing in the src folder. When I export to a JAR file though it can't find it. I know that you have to get the file as a resource, and I've done this before with images, but I can't get it to work with a file. I tried this, but it didn't work:

URL fileURL = this.getClass().getResource("config.txt");
File configFile = new File(fileURL);

But it won't compile, as it doesn't like the `newFile(fileURL)' portion. I've checked this out online, and found a bunch of stuff, but it all seems to relate to reading the file, and not simply adding it to the JAR. Can anybody help me out with this? Thanks.

user3226170
  • 175
  • 1
  • 1
  • 14

0 Answers0