Jump to content

  • Log In with Google      Sign In   
  • Create Account

FREE SOFTWARE GIVEAWAY

We have 4 x Pro Licences (valued at $59 each) for 2d modular animation software Spriter to give away in this Thursday's GDNet Direct email newsletter.


Read more in this forum topic or make sure you're signed up (from the right-hand sidebar on the homepage) and read Thursday's newsletter to get in the running!


Question on writing texts and strings to a binary file.


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 tom_mai78101   Members   -  Reputation: 577

Like
0Likes
Like

Posted 07 June 2013 - 12:54 PM

Using DataInput/OutputStreams to handle byte arrays:

 

  1. What do you usually do to handle text in a byte array just before writing the data to a file?
  2. Is it best practice to write texts and strings to a binary file over than to a text file when it comes to saving? (Not considering readability or compactness, but rather just usefulness)

Thanks.



Sponsor:

#2 Servant of the Lord   Crossbones+   -  Reputation: 21183

Like
0Likes
Like

Posted 07 June 2013 - 02:16 PM

I'm no pro, so I'd be interested to hear what others do as well.

 

1) For binary files that have text in them, I just write the size of the string and then the string itself - I don't do anything special to it.

2) I keep text-only data as plaintext files, for convenience of editing with tools like notepad, unless I have a reason why binary would be better.

 

Even things like std::maps or std::vectors I sometimes just load from comma-separated or newline-seperated text files for easier editing. Classes or structs I usually save to binary files or else plain-text config files with special syntax.

 

[Edit:] Oh, you were referring to Java specifically - my bad. My response comes from using C++.


Edited by Servant of the Lord, 07 June 2013 - 02:19 PM.

It's perfectly fine to abbreviate my username to 'Servant' rather than copy+pasting it all the time.
All glory be to the Man at the right hand... On David's throne the King will reign, and the Government will rest upon His shoulders. All the earth will see the salvation of God.
Of Stranger Flames - [indie turn-based rpg set in a para-historical French colony] | Indie RPG development journal

[Fly with me on Twitter] [Google+] [My broken website]

[Need web hosting? I personally like A Small Orange]


#3 Glass_Knife   Moderators   -  Reputation: 5054

Like
0Likes
Like

Posted 07 June 2013 - 03:28 PM

Using DataInput/OutputStreams to handle byte arrays:

 

  1. What do you usually do to handle text in a byte array just before writing the data to a file?
  2. Is it best practice to write texts and strings to a binary file over than to a text file when it comes to saving? (Not considering readability or compactness, but rather just usefulness)

Thanks.

 

I would expect to see classes implementing the java.io.InputStream and java.io.OutputStream interfaces used for bytes of data (not text), and classes implementing the java.io.Reader and java.io.Writer for messing with character streams.  There is nothing wrong with using an InputStream for text, but the reader and writer family have extra methods making text processing easier.  For instance, the BufferedReader.readLine() method that reads an entire line and returns it as a String.

 

If you do text stuff with straight input streams and output streams you can wind up re-inventing the wheel.


Edited by Glass_Knife, 07 June 2013 - 03:29 PM.

I think, therefore I am. I think? - "George Carlin"
Indie Game Programming




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS