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
41
votes
4 answers
Java - how do I write a file to a specified directory
I want to write a file results.txt to a specific directory on my machine (Z:\results to be precise). How do I go about specifying the directory to BufferedWriter/FileWriter?
Currently, it writes the file successfully but to the directory where my…

user726219
- 413
- 1
- 5
- 5
38
votes
1 answer
Read and Write Text in ANSI format
Please have a look at the following code
import java.io.*;
public class CSVConverter
{
private File csvFile;
private BufferedReader reader;
private StringBuffer strBuffer;
private BufferedWriter writer;
int startNumber = 0;
…

PeakGen
- 21,894
- 86
- 261
- 463
36
votes
8 answers
BufferedWriter not writing everything to its output file
I have a Java program that reads some text from a file, line by line, and writes new text to an output file. But not all the text I write to my BufferedWriter appears in the output file after the program has finished. Why is that?
The details: the…

golmschenk
- 11,736
- 20
- 78
- 137
19
votes
6 answers
FileWrite BufferedWriter and PrintWriter combined
Ok so I am learning about I/O, and I found the following code in one of the slides. can someone please explain why there is a need to have a FileWrite, BufferedWriter and PrintWriter? I know BufferedWriter is to buffer the output and put it all at…

Ahoura Ghotbi
- 2,866
- 12
- 36
- 65
16
votes
2 answers
Create a text file if it doesn't exist and append to it if it does using Java BufferedWriter
This is probably ridiculously simple for gun Java programmers, yet the fact that I (a relative newbie to Java) couldn't find a simple, straightforward example of how to do it means that I'm going to use the self-answer option to hopefully prevent…

Alan K
- 1,957
- 3
- 19
- 30
16
votes
6 answers
how to write an array to a file Java
I have been trying to write an array to a file. I know how to write integers or String to a file but to bring an array confuses me. I am using this right now:
public static void write (String file, int[]x) throws IOException{
BufferedWriter…

Lock1618
- 199
- 2
- 3
- 9
15
votes
4 answers
Is it necessary to close a FileWriter, provided it is written through a BufferedWriter?
Consider a BufferedReader as below:
writer = new BufferedWriter(new FileWriter(new File("File.txt"), true));
In this case at the end of the application, I am closing the writer with writer.close()
Will this be enough? Won't that FileWriter created…

vivek_jonam
- 3,237
- 8
- 32
- 44
12
votes
1 answer
BufferedWriter is not writing a new line in a file for a String having "\n" added to it
I was trying some stuff in Swing (Java), but getting very strange results.
I am getting a String from JTextArea.getText() method and adding "\n" to it. This resultant string I am writing into a file, using BufferedWriter which is chaining through…

user3769778
- 967
- 2
- 7
- 26
11
votes
6 answers
in what way is java.net.Socket threadsafe?
I have a Socket that I am both reading and writing to, via BufferedReaders and BufferedWriters. I'm not sure which operations are okay to do from separate threads. I would guess that writing to the socket from two different threads at the same time…

lacker
- 5,470
- 6
- 36
- 38
11
votes
3 answers
java : writing large files?
Greetings ,
I get huge number of records from database and write into a file.I was wondering what the best way to write huge files. (1Gb - 10Gb).
Currently I am using BufferedWriter
BufferedWriter mbrWriter=new BufferedWriter(new…

Ashika Umanga Umagiliya
- 8,988
- 28
- 102
- 185
10
votes
3 answers
Writing a file using multiple threads
I am trying to write a single huge file in Java using multiple threads.
I have tried both FileWriter and bufferedWriter classes in Java.
The content being written is actually an entire table (Postgres) being read using CopyManager and written. Each…

jayanth88
- 564
- 1
- 6
- 14
9
votes
0 answers
How to use a BufferedWriter in Python?
I am facing the following problem: I'm trying to implement a simulator for supply chains. These will produce a lot of EPCIS Events (events that occur at RFID readers). These events should then be written to a csv file in order to load them into any…

philgiese
- 623
- 1
- 7
- 17
9
votes
1 answer
Why default buffer size is 8k in Java IO?
The default buffer size is 8k in BufferedWriter of somewhere else. Why use 8k? Does larger buffer size improve the performance?

Hesey
- 4,957
- 6
- 31
- 31
9
votes
3 answers
why is bufferedwriter not writing in the file?
Here is the code snippet.
read = new FileReader("trainfiles/"+filenames[i]);
br = new BufferedReader(read);
while((lines = br.readLine())!=null){
st = new StringTokenizer(lines);
…

Maverick
- 2,738
- 24
- 91
- 157
9
votes
4 answers
How to set the buffer size on a BufferedWriter over a FileWriter
I met a problem with BufferedWriter when I write data to a single file with some threads.
I set the buffer size of the BufferedWriter, but no matter what number I set, it flushes the data to disk when the buffer is 8192 (the default buffer size),…

jinhong_lu
- 238
- 1
- 2
- 11