473,394 Members | 1,810 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Why the file.txt is not updated inside the IDE (using BufferedWriter)?

Hi all ,I came across the internet for such a method to write to a file,although I am taking java but never really learned about buffered writer instead I took Printstream class;my question is why the records of the file created using this method are not updated (if Ineed to add records) inside IntellijIdea,instead you have always to check the file using Notepad,thanks for any reply here is the code:

Expand|Select|Wrap|Line Numbers
  1. public void writeToFile(String filename){
  2.  
  3.  
  4.             BufferedWriter bufferedWriter = null;
  5.  
  6.             try {
  7.  
  8.                 // Construct the BufferedWriter object
  9.                 bufferedWriter = new BufferedWriter(new FileWriter(filename));
  10.  
  11.                 // Start writing to the output stream
  12.                 bufferedWriter.write("Writing line one to file");
  13.                 bufferedWriter.newLine();
  14.                 bufferedWriter.write("Writing line two to file");
  15.                 bufferedWriter.newLine();                        
  16.                 bufferedWriter.write("Writing line three to file");
  17.             } catch (FileNotFoundException ex) {
  18.                 ex.printStackTrace();
  19.             } catch (IOException ex) {
  20.                 ex.printStackTrace();
  21.             } finally {
  22.  
  23.                 // Close the BufferedWriter
  24.                 try {
  25.                     if (bufferedWriter != null){
  26.                         bufferedWriter.flush();
  27.                         bufferedWriter.close();
  28.                     }
  29.                 } catch (IOException ex) {
  30.                     ex.printStackTrace();
  31.                 }
  32.             }
  33.         }
Apr 8 '09 #1
2 2272
dmjpro
2,476 2GB
Please use "code tag". By the way i tested this code, it's running successfully. But what do you mean by "inside the IDE"?
Apr 9 '09 #2
JosAH
11,448 Expert 8TB
Each time you run that code it'll create a new file (the old contents are lost). If that's not what you want read the API documentation for the FileWriter class; it also has a constructor that appends your data to the already existing contents.

kind regards,

Jos
Apr 9 '09 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Konrad Den Ende | last post by:
I tried to write some Unicode-16 characters (that were displayed correctly, as expected, on the screen) to a file but it didn't work out very well. I have those in an char as well as a String. Both...
2
by: slukacs | last post by:
hello one and all, i am still new to java but becoming ever so more efficient. i need some advice and guidance on big strings. i am debugging a special counter that i created in java and i am...
1
by: Row | last post by:
Hi, I am having trouble writting from a JTextArea to a flat text file (locally) I have tried using string tokenizer to tokenize the string first but with no luck, Im stuck on the one :( im...
6
by: gauravkhanna | last post by:
import java.io.*; class Automation1 implements Runnable { int iterationCount=0; Thread t; FileReader fr; //FileWriter fw; BufferedReader br; ...
9
by: asenthil | last post by:
Hai to all,, i had to tried to retrive and write a single row to a file from the database.. But dont know to write all the retrived rows to a file from the database.. how to do that... ...
1
by: PvtBillPilgrim | last post by:
I need to write a method called save that takes a String as a parameter, and returns a boolean value. The parameter represents a filename, and the method should save the contents of one of my classes...
6
by: topala1984 | last post by:
hello all excuse my english, I`m a beginer in java and I want to remove duplicate cities + rearrenging file`s lines elements from one 150 mb file, in my file I have that: ...
2
by: minouparhizkar | last post by:
hi could anyone helping me to finish this i have no idea how to implement the program in java im trying to grabbing the pixel from image and then convert it to the txt file .i did that but it didnt...
2
by: redcodeheaven | last post by:
Hello all,I have 2 methods inside the same class ,for some reason I couldn't output the values to the file,I am always getting result null(because the data fields are Strings) as a value when I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.