The Best Way to Write Data in Java

Discussion in 'Mac Programming' started by jsmwoolf, Aug 23, 2011.

  1. jsmwoolf macrumors regular

    Aug 17, 2011
    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.
  2. lee1210 macrumors 68040


    Jan 10, 2005
    Dallas, TX
    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?

  3. jsmwoolf thread starter macrumors regular

    Aug 17, 2011
    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.
  4. naples98, Aug 24, 2011
    Last edited: Aug 24, 2011

    naples98 macrumors member


    Sep 9, 2008
    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.
  5. mrbash macrumors 6502

    Aug 10, 2008
    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.

Share This Page