Win a copy of Java Challengers this week in the Java in General forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • paul wheaton
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Liutauras Vilda
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Piet Souris
Bartenders:
  • salvin francis
  • Mikalai Zaikin
  • Himai Minh

Why are my output files blank?

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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).]
 
"The Hood"
Posts: 8521
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Shrieeeeeeeeeeek! .

(I just HAD to do that )
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic