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
6
votes
4 answers
Limit file size while writing in java
I need to limit the file size to 1 GB while writing preferably using BufferedWriter.
Is it possible using BufferedWriter or I have to use other libraries ?
like
try (BufferedWriter writer = Files.newBufferedWriter(path)) {
//...
…

hacker
- 342
- 1
- 4
- 14
6
votes
3 answers
DataOutputStream#writeBytes(String) vs BufferedWriter#write(String)
I would like to create a HTML file for my report. The content in the report can be created either by using BufferedWriter#write(String)
File f = new File("source.htm");
BufferedWriter bw = new BufferedWriter(new…

Java Beginner
- 1,635
- 11
- 29
- 51
5
votes
3 answers
Do I need to implement synchronized on writing data to a same file by using BufferedWriter and FileWriter?
I am working on Webmethods Integration Server. Inside there is a java service which is in form of a static java method for writing data to a log file (server.log) by using BufferedWriter and FileWriter. The static method code is like this:
public…

null
- 8,669
- 16
- 68
- 98
5
votes
4 answers
When should I close() a BufferedWriter?
I'm appending a line to a textfile each time a button is pressed. Currently I'm doing this each time the button is pressed:
...
try {
BufferedWriter bw = new BufferedWriter(new FileWriter(f, true));
if (fileIsNew == true)
…

intagli
- 286
- 4
- 5
- 20
5
votes
2 answers
Java - comparing string in ArrayList to all text in .txt file
The actual problem will be addressed a bit further down :), thanks.
I'm fairly new to Java (nearly through a 400 page book).
I'm not really that familiar with the API yet.
This is my best shot at reading a .txt file and checking if there are any of…

Mike Haye
- 793
- 3
- 12
- 22
5
votes
4 answers
Writing a formatted string to a file - Java
I have a string that I format with the System.out.format() method, I do something like :
System.out.format("I = %3d var = %9.6f", i, myVar);
but when I try to write this formatted string into a file, I only get something like…

T.Durand
- 77
- 2
- 11
5
votes
3 answers
Write file using BufferedWriter in Java
I am doing a lab where we have to read in an external file, take some statistics on the data, and then create and write a new file with the stats. Everything in my program works except for writing the file, which I cannot understand why my method…

Paidenwaffle
- 163
- 1
- 1
- 11
5
votes
3 answers
Deleting file contents android
I need to delete the contents of a file, before I write more information into it. I've tried different ways, such as where I delete the content but the file stays the same size, and when I start writing in it after the deletion, a blank hole appears…

kassy
- 51
- 1
- 2
4
votes
1 answer
use BufferedWriter to write same data to multiple files
I'm interested in writing some data I'm receiving into two different files (same data).
In my code, I'm using BufferedWriter and FileWriter to write the data to files, and I want, as a backup, to write the same data on the local storage and on the…

Geeky bean
- 475
- 6
- 21
4
votes
3 answers
What do I need to close when using PrintWriter in Java
When using a PrintWriter like this :
PrintWriter fileOut = new PrintWriter(new BufferedWriter(new FileWriter(csvFileIn)));
What do I need to close in the finally block ? The PrintWriter, the BufferedWriter and the FileWriter ?
Do I need to try…

JavaDev
- 307
- 1
- 3
- 16
4
votes
4 answers
How should I check if BufferedWriter is already closed?
In android, I am writing a file on clicking a button and on clicking next time, it saves the file and closes the buffered writer. But, I also want to implement functionality to close the buffered writer in onDestroy function. Before that I need to…

Astra Uvarova - Saturn's star
- 677
- 2
- 9
- 25
4
votes
1 answer
What is the best Scala thread-safe way to write to a BufferedWriter?
I have a simple method that writes a line of data to a File followed by a new line that is executed asynchronously.
def writeToFile(bw: BufferedWriter, str: String) = {
bw.write(str)
bw.newLine
}
When my program runs I'm getting "mixed…

ChickenSniper
- 71
- 4
4
votes
1 answer
Android - Persist file when app closes
I am creating a file in my Android application as follows:
HEADINGSTRING = new String("Android Debugging " + "\n"
"XML test Debugging");
}
public void setUpLogging(Context context){
Log.d("LOGGING", "Setting up…

Donal Rafferty
- 19,707
- 39
- 114
- 191
4
votes
8 answers
Java BufferedWriter close()
Assume that I have the following code fragment:
operation1();
bw.close();
operation2();
When I call BufferedReader.close() from my code, I am assuming my JVM makes a system call that ensures that the buffer has been flushed and written to disk. I…

rakeshr
- 1,027
- 3
- 17
- 25
4
votes
3 answers
Java read from one file and write into another file using methods
I am learning Java and working on File IO and right now stuck in reading text from One file and write in another file. I am using two different methods first one for reading and displaying text in console from file #1 and using another method to…

Newbie
- 103
- 2
- 3
- 13