Java class for writing text to a character-output stream, buffering characters so as to provide for the efficient writing of single characters, arrays, and strings.
Questions tagged [bufferedwriter]
754 questions
1
vote
1 answer
How PrintWriter can write to byte stream, but BufferedWriter cannot?
To start with I will provide a piece of code with comments:
FileOutputStream fos = new FileOutputStream ("test.txt");
//fos IS-A OutputStream as FileOutputStream extends OutputStream
PrintWriter pw = new PrintWriter (fos); //compiles (can take…

Stefan
- 969
- 6
- 9
1
vote
1 answer
How to write to a text file from an ArrayList
I'm trying to take data from an ArrayList of a class and write it into a text file. It creates the temporary file, but doesn't do anything with it. It prints what I'm trying to put in the file and doesn't delete the temporary file. What am I doing…

Eme
- 25
- 6
1
vote
1 answer
Why Java parallel file writing is not working?
I am trying to write a script that will run a .exe program 4 times with different parameters. I created one thread for each .exe run. Each thread will write an output file. My problem is that, it should write in parallel, but as you can you see on…

Shizuka Masuda
- 89
- 3
- 13
1
vote
1 answer
BufferedWriter is not writing data properly
What is wrong in the below code? in console it is printing proper data but in file there is no data. it is creating 0-byte file.
JsonObjectBuilder mainObj= Json.createObjectBuilder();
mainObj.add("delete",delete);
…
user14046507
1
vote
2 answers
java - PrintWriter with FileWriter and BufferedWriter
I'm at my wits end here.
I'm trying to print a few thousands of lines in a file, using the following:
BufferedWriter bw = new BufferedWriter(new FileWriter(fileName, true));
PrintWriter pw = new PrintWriter(bw, true);
The file…

kkudi
- 1,625
- 4
- 25
- 47
1
vote
1 answer
Time-efficient way to append to existing header in existing CSV file in Java?
I'd like to modify the first line or header, of an existing csv file by adding a string to the end of that line.
I've tried using BufferedWriter to do so, but I can only get it to append at the end of the file.
My working code:
public static…

BoredPanda
- 57
- 5
1
vote
1 answer
bufio.Reader read nothing from the file after bufio.Writer write
Codes are shown as follow:
package main
import (
"bufio"
"fmt"
"io"
"log"
"os"
)
func main() {
file, _ := os.OpenFile("test.txt", os.O_CREATE|os.O_RDWR|os.O_APPEND, 0666)
// write
writer := bufio.NewWriter(file)
…

Alexander
- 523
- 5
- 21
1
vote
1 answer
Appending a line to an existing text file but adds an extra blank line
I am trying to add a new line to an existing text file, which works but sometimes adds a blank line in between the old data and the new data
So I have a file with the data:
mouse
keyboard
And when adding, it adds it like…

ahsirk83
- 23
- 4
1
vote
2 answers
how can I add new lines in txt using java, and without empty spaces
When I am writing text in this txt file, there either is no space between the new string and the old existing string, or there is extra lines, which messes up my other algorithms.
public String writeStudent(String file, String name)
…

Steven Oh
- 382
- 3
- 14
1
vote
2 answers
System.out.printf(“%4d”) in BufferedWriter / FileWriter
I made a multiplication table. The problem is that the table is not ordered as it should.
If I want just to print it on the screen, then I use this System.out.printf(“%4d”). How can I resolve this problem with BufferedWriter?
Instead of this:
Irj be…

venndi
- 161
- 9
1
vote
2 answers
Problems using lambda expression
I have a problem with sorting the letters of a word, by the number of occurrences of the letters and if the letters appear the same number of times, it will be sorted at least lexicographically.
I have a code but I get compilation error on the site…

STRKLok
- 29
- 1
1
vote
1 answer
Is flush() useless for FileWriter since it has no buffer?
When you use the flush() method while using a BufferedWriter, that makes sense because you might want to clear the stream immediately so that the person doesn't have to wait until all the writes are done before the file is updated.
But when you are…

Allan Henriques
- 175
- 1
- 9
1
vote
1 answer
Writing to a CSV file, can't write to first line
try{
Writer rwrite = new BufferedWriter(new FileWriter(file, true));
rwrite.append(reservation.toString() + "\n");
rwrite.close();
}
catch(IOException e){
System.out.println("Could not open BufferedWriter.");
…

Sean
- 31
- 4
1
vote
1 answer
How can I force BufferedWriter to break up data at specific places?
I'm using a BufferedWriter to send data into a database, (I know this is not really what it's meant for... don't ask. Basically I need to log to a database but buffer the data so that we don't end up with a major bottleneck) and I'm running into the…

user9791370
- 339
- 1
- 10
1
vote
1 answer
PrintWriter vs BufferedWriter
I'm trying to transfer strings from my server to my client and I'm trying to find an explanation why when I'm using PrintWriter in my server the client receives the string while when I'm using BufferedWriter the client doesn't receive the string.
In…

JeyJ
- 3,582
- 4
- 35
- 83