# Java looking in wrong directory for XML [closed]

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())
System.out.println(fileNames);


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

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.

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 http://pastebin.com/59Nt7Dtd.

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).

• 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 : shrani.si/f/2H/13W/131vAM3/error3.png , 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
 path="/res/particles/file.xml";