Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (494)
Games in Android Showcase (114)
games submitted by our members
Games in WIP (563)
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 871 times)
0 Members and 1 Guest are viewing this topic.
Offline zulo

Junior Member




Java games rock!


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

hi

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:

1  
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

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


Should I use anything else than InputStreamReader maybe?
Offline digitprop

Junior Member





« 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 . www.digitprop.com
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!

http://wiki.java.net/bin/view/Games/JeffFAQ
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Dwinin (20 views)
2014-09-12 09:08:26

Norakomi (55 views)
2014-09-10 13:57:51

TehJavaDev (64 views)
2014-09-10 06:39:09

Tekkerue (32 views)
2014-09-09 02:24:56

mitcheeb (54 views)
2014-09-08 06:06:29

BurntPizza (38 views)
2014-09-07 01:13:42

Longarmx (24 views)
2014-09-07 01:12:14

Longarmx (28 views)
2014-09-07 01:11:22

Longarmx (28 views)
2014-09-07 01:10:19

mitcheeb (36 views)
2014-09-04 23:08:59
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org 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‑gaming.org
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!