Re: How to write Array of Object to a file?



Robert Larsen wrote:
DL wrote:
what is the best way to do this? any suggestions?

That depends on a lot of things. An XML file i very easily read by
humans and portable but often not very scalable. A database is very fast
and scalable. A binary file can be easy to work with (or very very hard).
What would be the typical usage ? And how many records would the file hold ?

There are gazillion ways to emit data. The simplest is to open a file for writing, say in a variable 'wr' -

import java.io.PrintWriter;
...
PrintWriter wr = new PrintWriter( someFileName );
...
wr.println( foo.getProperty().toString() );

Of course, 'toString()' in most cases will not give you what you want, but it's a start.

Really you should just read the Javadocs on the java.io package, and the tutorial:
<http://java.sun.com/docs/books/tutorial/essential/io/index.html>

--
Lew
.



Relevant Pages

  • Re: java.lang.OutOfMemory Error
    ... I am reading from the database and writing to PrintWriter ... The database returns around 50,000 rows. ... >length of the StringBuffer to zero. ... >as there are no object creations inside the loop and I am re-using the ...
    (comp.lang.java.programmer)
  • Re: PrintWriter as blob with mysql
    ... PrintWriter pw = new PrintWriter(new ... then i "insert" it in a blob field in a mysql table ... You can't pass that kind of thing through a database, especially since your using a socket output stream. ... Sockets are endpoints on one machine, you can't pass that to a database then then through on to another client. ...
    (comp.lang.java.help)
  • Re: PrintWriter as blob with mysql
    ... PrintWriter pw = new PrintWriter(new ... then i "insert" it in a blob field in a mysql table ... You don't really show us your code, so some parts of our responses must be speculative, however the field contents after you "insert" your PrintWriter show that it contains a string, not a Writer at all. ... It could be that your way of determining the contents is actually returning the default toStringof the PrintWriter or Blob object of interest, not the actual contents of the database field. ...
    (comp.lang.java.help)