-
May 10th, 2004, 03:34 AM
#1
PrintWriter grief
Ok, I'm dumping results to a text file via PrintWriter...
The problem is that each line I write to my text file overwrites the previous, so all I end up with is the final result... the Java Sun forums are unfortunately not helping.
Code:
File logFile = new File("C:/Correlate.log");
FileOutputStream logFileStream = new FileOutputStream (logFile);
PrintWriter writeFile = new PrintWriter (logFileStream);
try
{
if(writeFlag == 1)
{
//writeFile.println("\n\n");
writeFile.println(noSignature);
writeFile.println(Correlate.getFile() + "\r\n");
}
}
catch(Exception e)
{
System.out.println("Crap...oooops!!");
}
writeFile.close();
}
I've used the carriage returns...what am I missing? My other alternative is to use BufferedWriter, but for some reason that's not being recognized...
Grrr....lol
-
May 10th, 2004, 04:10 AM
#2
Now I really have to laugh
Just as a mindless aside, whenever I have a problem, or when I lose something... as soon as I ask, or buy a new whatever that I lost, I find it.
So if anybody cares, in order to make the lines show up one after another, one of the lines needs to be changed....DOH!!!
Code:
File logFile = new File("C:/Correlate.log");
FileOutputStream logFileStream = new FileOutputStream (logFile, true); <-- added true
PrintWriter writeFile = new PrintWriter (logFileStream);
If you do it like I did in the first example, every time you try to write to the file, it creates a new file... who knew??!!!
Now if I could just drill down through my directories like I want
-
May 10th, 2004, 07:47 AM
#3
hi
The problem is that each line I write to my text file overwrites the previous,
so all I end up with is the final result...
what happned to use the append() method.
Code:
f = new File("myFile.txt")
f.append("Hello World\n")
f.append("Hello again, that's me!")
-
May 10th, 2004, 02:36 PM
#4
what happned to use the append() method.
Actually, I didn't know one could use it that way. I'll tuck that info away for future reference though.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
|