Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I found this suggestion on a Stack Exchange site to print out what the current directory is:

File file = new File(".");
for(String fileNames : file.list()) 

Basically, when I run a game in Eclipse, I get this:

Enter image description here

But when I compile the game and run it, it prints out this (it prints out the stuff that is in the same directory as the JAR file is). Images, and sound are working fine. It's just the XML file that is causing this.

Enter image description here

How do I make Java read XML files from res folder like it does for images and sound in Eclipse?

My particular code that loads the XML is at

Slick2D documentation is at

share|improve this question

closed as off topic by bummzack, Nate, Anko, msell, Josh Petrie May 2 '13 at 15:21

Questions on Game Development Stack Exchange are expected to relate to game development within the scope defined by the community. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about reopening questions here.If this question can be reworded to fit the rules in the help center, please edit the question.

This question isn't really gamedev related. It would be better suited for stackoverflow – bummzack May 1 '13 at 20:58
But im using Slick2d, the particle class is from slick2d example page – Matthew May 1 '13 at 21:25
up vote 4 down vote accepted

The reason why it works in Eclipse is because you are in the project root when you do this:

particleImage = new Image("res/particles/particle.png", false);

For consistency, put your XML file there as well or if you don't want to run it from Eclipse, but from a JAR, integrate an absolute data path in your code (do not hardcode it in your source files).

share|improve this answer
how do i get absolute data path from code, i want to load evreything from project room /res – Matthew May 1 '13 at 20:53
@Matthew read the API documentation for the Java File class. – jwenting May 2 '13 at 6:01
Ok so i made it absolute path but now this happends : , so my question is shouldnt the absolute path have filename inluded, the name of the file was 5.jar but it was not shown in the absolute path – Matthew May 2 '13 at 10:16
The absolute path is composed out of: DirPath + RelativePath + Filename. If you are trying to get the jar, your dirPath should be something like C:\Project\Particles and your relativePath \res (\bin) and the filaname a.xml (b.jar). Hope this clarifies it a bit. – Cristina May 2 '13 at 10:19
Shouldnt the path be something like this for this case D:\PathToJar\game.jar\res\particles\particleXmlFile.xml , because the particlexml file is inside the game.jar – Matthew May 2 '13 at 10:33
 emitter = ParticleIO.loadEmitter(path);

This fixed the problem thanks to Cristina

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.