Streams

Hi..To generate a file from values contained in an object which File Stream do you think I should use?FileWriter or OutputStreamWriter?tnx in advance!!!
[194 byte] By [charllescubaa] at [2007-11-27 9:33:06]
# 1
Is there any requirement as to the format of the resulting file? What do you intend to use it for?
OleVVa at 2007-7-12 22:53:26 > top of Java-index,Java Essentials,Java Programming...
# 2
Both are for writing text, but using OutputStreamWriter allows you to specify the character encoding to be used explicitly, rather than using the default encoding java has decided your system uses. This might matter if you're using anything beyond standard ascii characters.
malcolmmca at 2007-7-12 22:53:26 > top of Java-index,Java Essentials,Java Programming...
# 3
Yes there is.Basically, Strings and numbers(int, double) have to be saved in the output file. Numbers have to be stored as if they were a sequence of characters:)
charllescubaa at 2007-7-12 22:53:26 > top of Java-index,Java Essentials,Java Programming...
# 4
OutputStreamWriter allows to specify a charsetFileWriter doesnt allow to specify a charsetFileWriter is subclass of OutputStreamWriter, isnt it? It should allow to specify charsets!!!Tnx
charllescubaa at 2007-7-12 22:53:26 > top of Java-index,Java Essentials,Java Programming...
# 5

The explanations in this article are pretty good...

http://java.sun.com/developer/technicalArticles/Programming/PerfTuning/

and there's always the good 'ole sun tutorials ...

and then there's your new best friend... Google...

Having said that, I think I'd probably use a PrintWriter ... something like this ...

private static int writeUnicode_PrintWriter(String fileName) {

//Approach 4: PrintWriter - handles Unicode chars properly.

try {

FileOutputStream fos = new FileOutputStream(fileName);

OutputStreamWriter osw = new OutputStreamWriter(fos, "UTF8");

PrintWriter pw = new PrintWriter(osw);

pw.println("\uffff\u4321\u1234");

pw.close();

} catch (IOException e) {

System.err.println(e);

}

return(0);

}

and then of course there's the XML option, which (just maybe) made easier with apache's XmlBeans.

Good luck. Keith.

corlettka at 2007-7-12 22:53:26 > top of Java-index,Java Essentials,Java Programming...
# 6
Thank uIt cleared some doubts I had:)
charllescubaa at 2007-7-12 22:53:26 > top of Java-index,Java Essentials,Java Programming...