Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

jsmwoolf

macrumors regular
Original poster
Aug 17, 2011
123
0
In Java, what's the best way to read and write data? Through text, binary, or XML?

In C, C++, and Objective-C I believe you can only write data in text and binary.
 
This is a pretty confusing question. In the end XML is text is binary, and you can write any of the three from all of the languages you mention. Which you use varies by situation. What do you need to write? What needs to read it?

-Lee
 
I'm trying to write numbers, Colors, and possibly boolean values which all three are based off of variables. The same goes for reading as well.
 
I'm trying to write numbers, Colors, and possibly boolean values which all three are based off of variables. The same goes for reading as well.

XML is just a properly formatted text document. If you open a binary file, you will see a lot of seemingly random characters. All of this can be read/written using Java.

From what it sounds like, you would probably be better off doing either XML or or just plain text. XML is really just a standard for writing text that is easily read by machines because it gives some context/meaning to the text.
 
Last edited:
Reading/Writing XML is going to be a bit more complicated than simple text files. If you don't have a specific need for XML, you may be better just to use text files.

Using XML is fine if you have to share the file between different programs and people, but if you are just reading/writing a file for one program, its not worth the additional hassle.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.