0

have a project in java(a pacman game) which uses some external files, for example a .txt for the level design and some images for the pacman and ghosts. Right now i have them all under the project folder and access them as follows:

Scanner s = new Scanner(new File("level1.txt"));

image = ImageIO.read(new File("PM0.gif"));

The project works fine if i run it through eclipse, however when i export it to a .jar executable it wont load any file properly. What is the simplest way to have these resources properly packaged and loaded? I am new to java programming(this is my first project) and i got very confused from some previous answers to this question(and none of them worked).

user19955
  • 75
  • 1
  • 5
  • I would put them under Java/main/resources – Jack Flamp Feb 27 '17 at 18:36
  • [Link to similar questions](https://www.google.com/webhp?sourceid=chrome-instant&ion=1&espv=2&ie=UTF-8#q=site:stackoverflow.com+java+where+to+put+resources&*) – Hovercraft Full Of Eels Feb 27 '17 at 18:48
  • A .jar file is actually a zip file with one or more special entries. An entry in a .jar archive is not a separate file, just a sequence of bytes in an archive, so you can never read it as a File object. See http://stackoverflow.com/documentation/java/2433/resources-on-classpath#t=201701111734535687024&a=remarks . – VGR Feb 27 '17 at 18:49

0 Answers0