473,320 Members | 1,876 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Binary file problem

35
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:

Expand|Select|Wrap|Line Numbers
  1.                      File aFile  = new File( "players.dat" );
  2.                      // create an output stream to the file
  3.                      FileOutputStream aFileOutStream = new FileOutputStream ( aFile, true );
  4.                      // create a data output stream to the file output stream
  5.                      DataOutputStream aDataOutStream = new DataOutputStream ( aFileOutStream );
  6.                      // write data to file
  7.                      aDataOutStream.writeUTF(player);
  8.                      aDataOutStream.writeUTF(String.valueOf(percent) );
  9.                      aDataOutStream.writeUTF(type );
  10.  
  11.                      aFileOutStream.close();
Feb 23 '08 #1
2 898
sukatoa
539 512MB
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:

Expand|Select|Wrap|Line Numbers
  1.                      File aFile  = new File( "players.dat" );
  2.                      // create an output stream to the file
  3.                      FileOutputStream aFileOutStream = new FileOutputStream ( aFile, true );
  4.                      // create a data output stream to the file output stream
  5.                      DataOutputStream aDataOutStream = new DataOutputStream ( aFileOutStream );
  6.                      // write data to file
  7.                      aDataOutStream.writeUTF(player);
  8.                      aDataOutStream.writeUTF(String.valueOf(percent) );
  9.                      aDataOutStream.writeUTF(type );
  10.  
  11.                      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)
Feb 24 '08 #2
saytri
35
Yeah good idea. Thanks a lot. :-)
Feb 24 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

9
by: Maurizio Penna | last post by:
I, guys. I've embeded an image into a xml file, something like that: <display type="picture" mime="image/png" name = "mosaico6.png"> <!]> </display> Now, I want to display it with a XSL...
3
by: Tanuki | last post by:
Hi All: I encounter a programming problem recently. I need to read a binary file. I need to translate the binary data into useful information. I have the format at hand, like 1st byte = ID,...
2
by: anirudhvr | last post by:
Hi, I needed a basic binary to ascii encoder, so I wrote this piece of code: /* Encoding algo: suppose 11111010 is the byte to be encoded. It is first broken up into two 4-bit parts (1111...
9
by: Ching-Lung | last post by:
Hi all, I try to create a tool to check the delta (diff) of 2 binaries and create the delta binary. I use binary formatter (serialization) to create the delta binary. It works fine but the...
3
by: John R. Delaney | last post by:
I am running in debugging mode after a clean C++ compilation under .NET 2003. In a BIG loop (controlled many levels up in the call stack), I open a file with fopen using the "a" option. Then I write...
4
by: knapak | last post by:
Hello I'm a self instructed amateur attempting to read a huge file from disk... so bear with me please... I just learned that reading a file in binary is faster than text. So I wrote the...
7
by: John Dann | last post by:
I'm trying to read some binary data from a file created by another program. I know the binary file format but can't change or control the format. The binary data is organised such that it should...
3
by: nguser3552 | last post by:
Hello Everyone, I have a problem I can't surmount, anything is gravy at this point. I need to be able to read any type of file .ext (mov,mpeg,mp3,etc) in binary format. I can do this in C, but ...
7
by: Ludo | last post by:
Hi, I'm working on an open source project and I have a problem with a binary file. When I read the binary file with the program downloaded from sourceforge, I have no problem. However, I'm unable...
10
by: rory | last post by:
I can't seem to append a string to the end of a binary file. I'm using the following code: fstream outFile("test.exe", ios::in | ios::out | ios::binary | ios::ate | ios::app)...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.