Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Most portable format for data

 
Emilio Gagliardi
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi just a quick question, what is the best way to store primitive types when writing to a file so that other programs can read/import the data? For example, excel or SPSS.

Cheers,
Emilio
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34837
369
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Emilio,
For Excel, a comma delimitted file is best.
 
Stefan Wagner
Ranch Hand
Posts: 1923
Linux Postgres Database Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
spss handles csv-files too.
 
Emilio Gagliardi
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is probably a dumb question but are CSV files written as char?
As in, if I want to store 123456 as an actual integer it would take 4 bytes, as opposed to 12 bytes to store the six characters...is that right? If so, then I must write the numbers and commas and end-of-line characters.

Thank you for your input. =)

Cheers,
 
Tim West
Ranch Hand
Posts: 539
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why not create a file in Excel and see how it saves it? You'll find, I think, that ultimately you have to write numbers in human-readable format. So I'd be going with a PrintWriter.


-Tim
 
Richard Rodger
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
CSV files are in a plain text human-readable format, so you would output all 6 characters.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic