Software that stores data in a flat file, which is a common encoding / file format method
I was messed with either using SQL server to store data or using xml files.
What are the common methods for storing data in flat files other than xml and CSV.
I know many times when I open the files, the data is all messed up, which means that it is encoded correctly?
Are there any general methods that I could read about somewhere?
source to share
Depending on your requirements. If it's human readable, then YAML, XML, and CVS are fine.
But if you need performance or preserving binary values โโ(like an 8 byte double) then personally I create my own file format using Java's excellent DataOutputStream and DataInputStream. But be careful when creating your own format. You don't want to share it with the world at all, otherwise you will need to worry about security and extensibility. You always need to take care of the data integrity and maybe add crc checksums.
Getting the flat binaries right is tricky, so make sure you really need one and ask for help!
source to share
YAML is a human-friendly data serialization standard for all programming languages.
Example (again, from the site ):
Below is an example of an invoice expressed in YAML (tm). The structure is shown through padding (one or more spaces). Sequence elements are denoted by a pair of dashes and key values โโwithin the map, separated by a colon.
invoice: 34843
date : 2001-01-23
bill-to: &id001
given : Chris
family : Dumars
address:
lines: |
458 Walkman Dr.
Suite #292
city : Royal Oak
state : MI
postal : 48046
ship-to: *id001
product:
- sku : BL394D
quantity : 4
description : Basketball
price : 450.00
- sku : BL4438H
quantity : 1
description : Super Hoop
price : 2392.00
tax : 251.42
total: 4443.52
comments: >
Late afternoon is best.
Backup contact is Nancy
Billsmer @ 338-4338.
source to share
The file that "messed up" everything does not mean that it is encoded. this means that it is saved in some binary format, not text format.
When you save in binary, you simply write the data as if it were in program memory. for instace to write an integer you write 4 bytes of integer directly and don't convert it to text. This has the advantage of saving space. If you open such a file with notepad, all you see are random characters.
source to share
Out of completeness, I mentioned archaic . ini format , but I can't imagine not writing flat file data to XML or YAML is not working.
source to share