Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (748)
Games in Android Showcase (226)
games submitted by our members
Games in WIP (834)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  PrintWriter problems  (Read 1549 times)
0 Members and 1 Guest are viewing this topic.
Offline zulo

Junior Devvie

Java games rock!

« Posted 2004-03-24 19:42:11 »


Im trying to save an int[] to a file, where each int is printed to a new line in a file. When the program is run from eclipse and is not jarred the file is saved to the parent map even when I havent specified any special map.

I use a printwriter like this:

PrintWriter(new FileWriter(filename+fileEnding), true);

I have tried to use "/filename.txt" but that doesnt change anything. Also when I try to load the file it works, but when i put the program in a jar it saves the file outside the jar,and it should, but it cant load the file because it doesnt find it.

What is the correct syntax for specifying the directory that the jar file is in?

This is what I use to read in the file line by line

new BufferedReader(new                       InputStreamReader(getClass().getResourceAsStream("./"+mapname+fileEnding)));

Should I use anything else than InputStreamReader maybe?
Offline digitprop

Junior Devvie

« Reply #1 - Posted 2004-04-04 09:51:09 »

getResourceAsStream() searches for the file in the class context of the class for which it is called. Thus, if the class is inside a JAR, the file will be searched inside the JAR as well.

Therefore, do not use getResourceAsStream() for things such as INI files, where the file must be somewhere in the file system, out of the INI file.

Alternatively, you could use the java.util.prefs package, which is a platform-independent mechanism to store and load systems and user settings.

M. Fischer .
Offline Jeff

JGO Coder

Got any cats?

« Reply #2 - Posted 2004-04-04 20:36:34 »

This is true but a bit incomplete.

It will actually look in its parent class loaders' environment first, just as  it does for classes.  (In fact these calla are used to find the bits for classes.)

Asd the root of all class loader parental lists should be the boot class loader, follwoed by the classpath loader, it will find anything that is in your classpath.

Got a question about Java and game programming?  Just new to the Java Game Development Community?  Try my FAQ.  Its likely you'll learn something!
Pages: [1]
  ignore  |  Print  

xxMrPHDxx (319 views)
2017-12-31 17:17:51

xxMrPHDxx (101 views)
2017-12-31 17:15:51

xxMrPHDxx (151 views)
2017-12-28 18:11:33

Ecumene (331 views)
2017-09-30 02:57:34

theagentd (497 views)
2017-09-26 18:23:31

cybrmynd (535 views)
2017-08-02 12:28:51

cybrmynd (475 views)
2017-08-02 12:19:43

cybrmynd (452 views)
2017-08-02 12:18:09

Sralse (412 views)
2017-07-25 17:13:48

Archive (1318 views)
2017-04-27 17:45:51
Java Gaming Resources
by philfrei
2017-12-05 19:38:37

Java Gaming Resources
by philfrei
2017-12-05 19:37:39

Java Gaming Resources
by philfrei
2017-12-05 19:36:10

Java Gaming Resources
by philfrei
2017-12-05 19:33:10

List of Learning Resources
by elect
2017-03-13 14:05:44

List of Learning Resources
by elect
2017-03-13 14:04:45

SF/X Libraries
by philfrei
2017-03-02 08:45:19

SF/X Libraries
by philfrei
2017-03-02 08:44:05 is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!