game file?

i got trouble in reading/writing my game state into file
this is all about reading/writing STRING object into file

first, can i add String into the end of file?
(without have to rewrite all from the beginning)
i use FileWriter, BufferedWriter, and PrintWriter to do file writing.
like this :


      private void fileWrite(String[] data,File fileName) {
      try {
            FileWriter out = new FileWriter(fileName);
            BufferedWriter writeOut = new BufferedWriter(out);
            PrintWriter fos = new PrintWriter(writeOut);

            fos.println(data.length);
            for (int i=0;i < data.length;i++)
                  fos.println(data[i]);
            fos.close();
      } catch (IOException e) { e.printStackTrace(); }
      }

the String[] data is not append to the end of file, but make a new file.

second, how to read n line of file.
example i want to read line 27 of my file to line 36
and replace that lines, then write it to the same file again.

thanxx anyone

Will people please stop cross posting from JDC? It’s annoying to answer the question once, then see it again. Pick a site (usually JDC for newbie questions) and post there. And BTW, this has nothing to do with Java2D. It should be under Newless Clewbies.

don’t get angry jbanes :wink:
i know i post in many forums :stuck_out_tongue:
cos i really need it fast
i got three forums that i really like, and
the answers always different and give me fast solutions ;D
i want to finish my game quick so there’s nothing wrong with this isn’t it?
by the way thanx jbanes, you are the best answer!! :slight_smile:

yeah but most people here are the same people as at the JDC games programming section.

[quote]don’t get angry jbanes :wink:
i know i post in many forums :stuck_out_tongue:
cos i really need it fast
[/quote]
If you need it that fast, then I suggest you find someone you can pay to give you the answer. People on these forums are doing this out of the goodness of their hearts. If you annoy them, they’ll stop answering your questions.

eeeh, not only has jbanes fallen out of the wrong side of bed, he landed on a half-eaten kebab from the night before and then tripped on a roller skate at the top of the stairs whilst hunting for the aspirin.

role

  1. You can open a FileWriter in append mode. Look at the docs for the constructor. Then any writes you do will go on the end
  2. You can’t just replace lines in a file as they might be any old length. You will have to read the whole file in line by line into an array of String[]s, replace the ones you want to replace, and write them out again. There are some optimisations but too complex to warrant bothering with for game work.

Cas :slight_smile:

Hrumph. This is exactly what I’m talking about. You’ve just wasted your time giving the same answer that SpongeBob and I gave over on JDC. I have no problem with visiting multiple forums. I just hate it when people immediately cross post “because they need it fast”. They don’t need it fast. If they needed it fast they wouldn’t be using forums. Reminds me of my son. When he sees the candy machine, he starts saying “Mommy, I need, I need!”

Plain and simple. It’s polite to post your question in one place, then seek the answer elsewhere only if the original source couldn’t help you.

Yeah, but I want to find out what rank comes after YaBB God :wink:

Cas :slight_smile:

lol

yeah - somewhere along the lines, they forgot demi-god :-/
ohh well, probably über god, or ultra lord :smiley:

okey, sorry sorry jbanes, fiuhh it’s hot here :slight_smile:
i didn’t mean annoying anybody here
i don’t know that most people here are the same people as at the JDC games programming section. sorry for that :stuck_out_tongue:

[quote]Plain and simple. It’s polite to post your question in one place, then seek the answer elsewhere only if the original source couldn’t help you.
[/quote]
yeah it’s nice. but then, i got very slow internet connection here, and i can’t use ‘this’ thing too often. :’(
so if i post and then got no answer at all. i have to post it again in other forum yuck
btw, i think everybody have different technic/answer to do something in programming, so there’s nothing wrong with asking to many people/forums isn’t it

[quote]It should be under Newless Clewbies.
[/quote]
ummm my question still about game, of course i post it here.
i think maybe someone here got a better game file instead what i’m doing now (using io operation)

okay, i’m sorry for annoying :-X

and thanxx for the answer jbanes and princec,
my game file is perfect now, you are the best guys!