I am somewhat confused about the two methods to save (and retrieve a file): BS and TOS.
What are the advantages and disadvantages to use one instead of the other and, more important, which is the best method according to whatever the application does (i.e. text, drawing, database, etc)?
I imagine it is a complicated issue, I just need the flavor of it.
binary save/load bytes without any conversion and text save everything as string type.
if you save a integer type as string in TextOutputStream you can open in editor and read it.
if you will save raw data of an picture you would use binary.
binary is faster.
text output is problematical because this conversion between types.
the benefit of a text file for a app settings is you can edit / change it in a text editor.
a JSON file is also text/string.
Anything you can do with a BinaryStream you can do with a TextxxxStream and vice versa. The difference is in the convenience methods each provides. Text streams have ReadLine/WriteLine methods that make dealing with text files easier. Binary streams allow you to set the read/write position and do random access. They also make writing binary data easier.
You can easily read/write picture data with a Text stream.
You can use a Binary stream to process a text file by reading the entire file into memory and splitting on EndOfLine.
That’s not a benefit. Users may just put invalid values in there and your app would crash.
The Apple’s HIG state, at least when I read it the last time, that you should have a preferences window as the only place to let the user change settings; not allow easy editing in a text file (unless special cases, like a computing-research center, where you know your users know enough about computers).
Yes, you can. You’ll probably see unprintable characters and such, but you can.
You can use whatever extension you want ?
Just consider the .rtf or .ini files as examples.
Hmm That would be string, not text.
[quote=491467:@Emile Schwarz]And you read and write the files using the same kind of instructions:
.txt: TextInputStream, TextOutputStream,
That’s up to you to decide. ini files, rtf documents (etc.) or your own files may just read&write text files, although their extension isn’t .txt.
For the ease of use, I’d say you have to take the correct decision. If you want to avoid as much as conversion, the BinaryStream is preferable, for instance (somewhat like avoiding the variant type everywhere in code).
[quote=491708:@Arnaud Nicolet]That’s not a benefit. Users may just put invalid values in there and your app would crash.
The Apple’s HIG state, at least when I read it the last time, that you should have a preferences window as the only place to let the user change settings; not allow easy editing in a text file (unless special cases, like a computing-research center, where you know your users know enough about computers).[/quote]
text is useful for developers, xml & json is used at business apps. ms also used ini files.
not every user is stupid. yes you can break something but also repair.