Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (775)
Games in Android Showcase (230)
games submitted by our members
Games in WIP (856)
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 1671 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  

hadezbladez (45 views)
2018-11-16 13:46:03

hadezbladez (48 views)
2018-11-16 13:41:33

hadezbladez (26 views)
2018-11-16 13:35:35

hadezbladez (20 views)
2018-11-16 13:32:03

EgonOlsen (1897 views)
2018-06-10 19:43:48

EgonOlsen (1936 views)
2018-06-10 19:43:44

EgonOlsen (1286 views)
2018-06-10 19:43:20

DesertCoockie (1717 views)
2018-05-13 18:23:11

nelsongames (1411 views)
2018-04-24 18:15:36

nelsongames (2041 views)
2018-04-24 18:14:32
Deployment and Packaging
by mudlee
2018-08-22 18:09:50

Java Gaming Resources
by gouessej
2018-08-22 08:19:41

Deployment and Packaging
by gouessej
2018-08-22 08:04:08

Deployment and Packaging
by gouessej
2018-08-22 08:03:45

Deployment and Packaging
by philfrei
2018-08-20 02:33:38

Deployment and Packaging
by philfrei
2018-08-20 02:29:55

Deployment and Packaging
by philfrei
2018-08-19 23:56:20

Deployment and Packaging
by philfrei
2018-08-19 23:54:46 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!