Binary file problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • saytri
    New Member
    • Dec 2007
    • 35

    Binary file problem

    I am writing to a binary file. My poblem is that i want that the next time it write to the file it will write on a new line. What can i do? Thanks a lot.

    This is the piece of code that writes to the file:

    Code:
                         File aFile  = new File( "players.dat" );
                         // create an output stream to the file
                         FileOutputStream aFileOutStream = new FileOutputStream ( aFile, true );
                         // create a data output stream to the file output stream
                         DataOutputStream aDataOutStream = new DataOutputStream ( aFileOutStream );
                         // write data to file
                         aDataOutStream.writeUTF(player);
                         aDataOutStream.writeUTF(String.valueOf(percent) );
                         aDataOutStream.writeUTF(type );
    
                         aFileOutStream.close();
  • sukatoa
    Contributor
    • Nov 2007
    • 539

    #2
    Originally posted by saytri
    I am writing to a binary file. My poblem is that i want that the next time it write to the file it will write on a new line. What can i do? Thanks a lot.

    This is the piece of code that writes to the file:

    Code:
                         File aFile  = new File( "players.dat" );
                         // create an output stream to the file
                         FileOutputStream aFileOutStream = new FileOutputStream ( aFile, true );
                         // create a data output stream to the file output stream
                         DataOutputStream aDataOutStream = new DataOutputStream ( aFileOutStream );
                         // write data to file
                         aDataOutStream.writeUTF(player);
                         aDataOutStream.writeUTF(String.valueOf(percent) );
                         aDataOutStream.writeUTF(type );
    
                         aFileOutStream.close();

    If me to implement that kind of operation...

    I will put the values from file to my variables, for example, String arrays...
    Then i will extend the length of the array... inserting a newline '\n',
    then what ever i like to add to that file, simply insert them after the inserted newline, then right it again...

    Correct me if im wrong,
    Sukatoa (Shadow Shaman)

    Comment

    • saytri
      New Member
      • Dec 2007
      • 35

      #3
      Yeah good idea. Thanks a lot. :-)

      Comment

      Working...