Questions tagged [bufferedwriter]

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.

754 questions
9
votes
4 answers

Is PrintWriter buffered?

I know that the PrintWriter is really good if we want to write formatted data, and I also know the use of BufferedWriter to improve IO performance. But I tried something like this, PrintWriter pw = new PrintWriter(System.out); pw.println("Statement…
Aritra Roy
  • 15,355
  • 10
  • 73
  • 107
9
votes
3 answers

writing a csv file using Buffered writer in Java

I am writing a csv file using buffered writer in java. My data is written correctly but I want to have different columns under which the data comes, Currently it is writing each instance of date in one row but not separated by columns. The code is…
Wearybands
  • 2,438
  • 8
  • 34
  • 53
8
votes
1 answer

Java - Do not overwrite with bufferedwriter

I have a program that add persons to an arraylist. What I'm trying to do is add these persons to a text file as well but the program overwrites the first line so the persons get erased. How do I tell the compiler to write at the next free…
user1051477
  • 117
  • 1
  • 8
8
votes
1 answer

Java BufferedWriter, OutputStreamWriter able to write to closed FileOutputStream

I was expecting the following code to throw an exception when I goto write data to the Stream: File file = new File("test.txt"); FileOutputStream fs = new FileOutputStream(file); OutputStreamWriter ow = new OutputStreamWriter(fs); BufferedWriter…
craineum
  • 187
  • 1
  • 2
  • 7
8
votes
4 answers

Java BufferedWriter Creating Null Characters

I've been using Java's BufferedWriter to write to a file to parse out some input. When I open the file after, however, there seems to be added null characters. I tried specifying the encoding as "US-ASCII" and "UTF8" but I get the same result.…
SortingHat
  • 727
  • 3
  • 15
  • 30
8
votes
5 answers

BufferedWriter writes over existing file

I'm trying to create a program which saves text on a file and then text can be added onto the file. However, every time i try to write to the file, it overwrites it and doesn't write anything. I need it to add whatever information i want it UNDER…
Victor Strandmoe
  • 113
  • 1
  • 2
  • 7
8
votes
3 answers

Access is denied when using FileOutputStream

I'm having an issue getting this to work. It takes in a string which consists of several pieces of information put together. However, when I try to write the String to a file in order to track changes in the program over time, I receive an access…
Nick
  • 191
  • 1
  • 2
  • 9
8
votes
4 answers

bufferedwriter stops in the middle of writing

For some reason this code results in a truncated text.txt file. It should (according to me) write out 1000 results, but the output file has various amounts of lines (depending on the run). Weirdly, the writing to the file stops in the middle of the…
user1602004
  • 107
  • 1
  • 7
7
votes
3 answers

How can I format the data written to a text file to be done in columns?

Hi I have a bunch of data Im writing to a text file, each line of the rows holds about 4 different pieces of data, I want to make it so that each type is data is aligned in rows. Here is the line that writes the data. output.write(aName + " " +…
Beef
  • 1,413
  • 6
  • 21
  • 36
7
votes
1 answer

Reading and Writing to the same file simultaneously in java

How can I access data in my file without first closing my BufferedWriter? import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.File; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public…
Karan Kulwal
  • 103
  • 1
  • 8
7
votes
1 answer

How to save a 2D array into a text file with BufferedWriter?

I'm trying to store a 2D array in a text file with BufferedWriter and I would also like to retrieve a 2D array from a text file and display in its original array format with BufferedReader. I have little experience with both methods. The desired…
7
votes
3 answers

Schrodinger's bug, BufferedWriter doesn't write into TXT unless manually checked

I am a rookie programmer-wanna-be and came across this problem I couldn't find the answer for. I use Eclipse, and for the program I use slick and lwjgl-2.9.3 The following code is in a state, inside the public void update(...) I have the problem…
7
votes
2 answers

Do we really need to call flush() just before close() today?

I read this question Using flush() before close() , and the accepted answer is this only means you follow the pattern. Just like BufferedWriter#close() or FilterOutputStream.#close() , if all of buffered Stream/Writer will call its flush() when we…
JaskeyLam
  • 15,405
  • 21
  • 114
  • 149
7
votes
3 answers

Strange behavior in writing to file

I was trying some basic Java I/O operations, I try to run the below code : public static void main(String[] args) { File file = new File("fileWrite2.txt"); // create a File object try { FileWriter fr = new FileWriter(file); …
Twaha Mehmood
  • 737
  • 3
  • 9
  • 26
7
votes
5 answers

Java: CSV File Easy Read/Write

I'm working on a program that requires quick access to a CSV comma-delimited spreadsheet file. So far I've been able to read from it easily using a BufferedReader. However, now I want to be able to edit the data it reads, then export it BACK to the…
Rich Young
  • 337
  • 2
  • 4
  • 10
1
2
3
50 51