Jump to content


Cant find the file!


1 reply to this topic

#1 User

    New Member

  • Members
  • Pip
  • 6 posts

Posted 26 March 2007 - 05:57 PM

I've got simple game which is loading its level from txt file as tilemap. Level just call method loadMap(String file) which start looks like this:

BufferedReader reader = new BufferedReader(new FileReader(subor));

while (true)

{

String line = reader.readLine();

// If reader hit the end of file

if (line == null)

{

reader.close();

break;

}

After this method is searching in file and depend on founded charakter it load for example wall etc - not important.
I've compiled it to jar file and start it home and it works. Then I've tried
to start it on 2 another computer but it doesnt work. It couldnt find the file. It says that System cannot find the file. File is in folder res . I call method wit parameter "res/level.txt". As I said it works on my pc but on the other the IOException is thrown. I've tried to copy res folder on every place in jar file of my game but it doesn't work. I dont know where is problem and I need to show it in school tomorrow so I've only a little time. Please help :(. Btw in res folder are another files like pictures and with them there is no problem (but there are loaded by another class and another way but parameter of method is same "res/filename")Maybe I've compiled it badly Iam using Eclipse fat jar plugin. Btw on every pc which I've tried it on are Windows xp with SP2 and Jre 1.6 (or jdk 1.6 for compile).

#2 SamuraiCrow

    Senior Member

  • Members
  • PipPipPipPip
  • 459 posts

Posted 27 March 2007 - 01:22 AM

Having an if...break sequence inside an unconditional loop is considered bad form. Also, you are missing a curly brace in the code you have displayed here. I don't think any of these problems would cause what you are describing though.

while((line=reader.readLine())!=null)
{
...

I don't see anything really wrong with your code apart from coding style. What is the default directory that you are running the program from?

If you try something like:

java c:\this\is\a\long\path\to\my\jar\file

it will run from the directory you started in. If you try something like:

cd c:\this\is\a\long\path\to\my\jar
java file

it will run in the correct directory.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users