Java-Gaming.org
Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
Featured games (78)
games approved by the League of Dukes
Games in Showcase (406)
games submitted by our members
Games in WIP (293)
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 682 times)
0 Members and 1 Guest are viewing this topic.
Offline zulo

Junior Member




Java games rock!


« Posted 2004-03-24 20: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 11: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 22: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.

Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
 
Get high quality music tracks for your game!

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

The first screenshot will be displayed as a thumbnail.

The invasion has landed! On Mars! And you're there to beat 'em!
cubemaster21 (84 views)
2013-05-17 21:29:12

alaslipknot (92 views)
2013-05-16 21:24:48

gouessej (123 views)
2013-05-16 00:53:38

gouessej (117 views)
2013-05-16 00:17:58

theagentd (127 views)
2013-05-15 15:01:13

theagentd (114 views)
2013-05-15 15:00:54

StreetDoggy (158 views)
2013-05-14 15:56:26

kutucuk (180 views)
2013-05-12 17:10:36

kutucuk (180 views)
2013-05-12 15:36:09

UnluckyDevil (187 views)
2013-05-12 05:09:57
Complex number cookbook
by Roquen
2013-04-24 12:47:31

2D Dynamic Lighting
by Oskuro
2013-04-17 16:46:12

2D Dynamic Lighting
by Oskuro
2013-04-17 16:45:57

2D Dynamic Lighting
by Oskuro
2013-04-17 16:23:20

Noise (bandpassed white)
by Roquen
2013-04-05 17:36:01

Noise (bandpassed white)
by Roquen
2013-04-03 16:17:38

Java Data structures
by Roquen
2013-03-29 13:21:12

Topic Request
by kutucuk
2013-03-22 21:42:01
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!
Page created in 0.775 seconds with 21 queries.