• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Why are my output files blank?

 
Reid Hattaway
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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);
write1.write(tmp1);
write2.write(tmp2);}
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
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is what is needed:
write1.write(temp1);
write1.flush();
write1.close();
[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"
Sheriff
Posts: 8521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Shrieeeeeeeeeeek! .

(I just HAD to do that )
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic