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
2
votes
3 answers
BufferedWriter.newLine() except after the last line
I'm drawing a blank on this. The problem I'm facing is I don't want a newLine() created after the last line is written to the new file. How can I accomplish this?
while (((aLine = reader.readLine()) != null)) {
…

notAChance
- 1,360
- 4
- 15
- 47
2
votes
1 answer
Interlacing BufferedWriter and PrintWriter
Is it safe to interlace BufferedWriter and PrintWriter in Java? Consider the following example:
private void writeToFile(File file, String text, Throwable throwable) throws Exception { // I use the "throws Exception" here for simplicity of the…

user7291698
- 1,972
- 2
- 15
- 30
2
votes
2 answers
Storing String input in a file
Ok, before anyone starts flaming me for asking "dumb" questions, please note that I have pretty much exhausted every other option that I know of and come up empty handed. Still if you feel like it, please go ahead and downvote/report this…

404 Brain Not Found
- 595
- 3
- 19
2
votes
1 answer
How to write line by line in file using buffered writer?
Here is my code to write the text in file line by line
public class TestBufferedWriter {
public static void main(String[] args) {
// below line will be coming from user and can vary in length. It's just an example
String data =…

scott miles
- 1,511
- 2
- 21
- 36
2
votes
2 answers
How to get acess to buffer in BufferedWriter
I am writing a file in java with BufferedWriter. Here is my code -
public static void main(String[] args) {
try(BufferedWriter writer = Files.newBufferedWriter(filePath, Charset.forName("CP1252"))) {
while (thereIsContentToWrite){
…

Gandhali Ambike
- 43
- 6
2
votes
2 answers
Write a String to a File in the Assets Folder
I have a .txt file in my Assets folder.
I tried using
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(getAssets().open("---.txt")));
I get an error underlining (getAssets().open("---.txt"))); Saying…

Eddie
- 171
- 5
- 13
2
votes
0 answers
What is the preferred file write approach for write ahead logging?
I am implementing write ahead logging as part of our application data recovery (application is in JAVA). Latency is a concern so I need to do buffered write instead of sync writes.
Looking at the BufferedOutputStream implementation, I realized that…

mithya
- 363
- 1
- 10
2
votes
1 answer
Why BufferedWriter doesn't print data for the 2nd time?
I am using a linked-list. The node class (for the linked-list) is like this:
public class node {
String data;
node next;
node previous;
}
In class stack, which uses node class, I've written a method print() to print values, print() is…

HMD
- 468
- 1
- 5
- 21
2
votes
2 answers
BufferedWriter isnt writing to file
I have to take name and address of user from user and put it into textfile. I write following code:
package selfTest.nameAndAddress;
import com.intellij.codeInsight.template.postfix.templates.SoutPostfixTemplate;
import java.io.*;
import…

Himal Acharya
- 836
- 4
- 14
- 24
2
votes
1 answer
BufferedWriter only write if not written before
I'm making a configuration class. I want it to write only if the BufferedWriter has not written to the name. If it has written to the name it updates that value. I'm not sure how to do this. Here is my write function so far.
public void…

TotallyGamerJet
- 339
- 1
- 2
- 12
2
votes
2 answers
Read and edit the file from Java
I'm trying to introduce a line break at every 100th character of the line from the existing file.But it doesn't write anything to it. below is the code written in java to read the existing file and write to it with a temporary file.
import…

eshaa
- 386
- 2
- 7
- 26
2
votes
1 answer
Java: BufferdWriter prints String into two lines for no reason?
I am currently writing a "text check" program in Java, but somehow I got stuck whilst creating an unique identifier for every file.
Actually I create an new identifier like this:
String identifier = Base64.encode((dateFormat.format(date) + "#" +…

Adrian K.
- 33
- 6
2
votes
1 answer
How does buffered I/O reduce the overhead which would occur if unbuffered I/O was used?
From this tutorial,
Most of the examples we've seen so far use unbuffered I/O. This means
each read or write request is handled directly by the underlying OS.
This can make a program much less efficient, since each such request
often…

Solace
- 8,612
- 22
- 95
- 183
2
votes
1 answer
Is there a maximum limit for the number of lines written in file?
I have created an application that writes a file line by line.
My question is: Is there a maximum limit for the number of lines written in file?
I would need to write files containing 2000000 lines or more.

Andreea Madalina
- 65
- 6
2
votes
1 answer
access denied to access to /etc/hosts
i can't access to hosts file of windows with java (just write) :
java.io.FileNotFoundException: C:\Windows\system32\drivers\etc\hosts (Access is denied)
at java.io.FileOutputStream.open(Native Method)
when i want append my text to hosts file get…

Abolfazl74
- 129
- 11