File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Why are my output files blank? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Why are my output files blank?" Watch "Why are my output files blank?" New topic

Why are my output files blank?

Reid Hattaway

Joined: Jul 15, 2001
Posts: 7
Sorry if anyone shrieks while reading this code. I would like to dump the contents of two vectors (Bingo and Key) into two dynamically named files. Here's my code so far:
String strWordSize = Integer.toString(wordSize);
String FileString1 = "Bingo" + strWordSize + ".txt";
String FileString2 = "Bingo" + strWordSize + "Key.txt";
File out1 = new File(FileString1);
File out2 = new File(FileString2);
FileWriter output1 = new FileWriter(out1);
FileWriter output2 = new FileWriter(out2);
BufferedWriter write1 = new BufferedWriter(output1);
BufferedWriter write2 = new BufferedWriter(output2);
String tmp1 = new String();
String tmp2 = new String();
for(int i = 0; i < Bingo.size(); i++){
tmp1 = (String) Bingo.get(i);
tmp2 = (String) Key.get(i);
When i first tried this, I didn't try using a BufferedWriter at all (Oy Vey, so many i/o streams in this language!); i tried using FileWriter(File file, Boolean append), but I continually got compilation errors when i tried lines such as FileWriter(out1, TRUE) or FileWriter(out1,Flag) where Flag is a previously declared and instantiated Boolean set to "TRUE". Either i dont understand Booleans (quite possible) or I dont understand how to invoke this particular constructor (very likely).
The above code compiles w/ no errors. It creates the two files w/ the appropriate names, but both files are blank. What's the problem.
Paul Selby
Ranch Hand

Joined: Oct 20, 2000
Posts: 41
This is what is needed:
[This message has been edited by Paul selby (edited July 16, 2001).]
[This message has been edited by Paul selby (edited July 16, 2001).]
[This message has been edited by Paul selby (edited July 16, 2001).]
Cindy Glass
"The Hood"

Joined: Sep 29, 2000
Posts: 8521
Shrieeeeeeeeeeek! .

(I just HAD to do that )

"JavaRanch, where the deer and the Certified play" - David O'Meara
I agree. Here's the link:
subject: Why are my output files blank?
It's not a secret anymore!