Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within OCPJP
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Jeanne Boyarsky
Ron McLeod
Paul Clapham
Liutauras Vilda
Sheriffs:
paul wheaton
Rob Spoor
Devaka Cooray
Saloon Keepers:
Stephan van Hulst
Tim Holloway
Carey Brown
Frits Walraven
Tim Moores
Bartenders:
Mikalai Zaikin
Forum:
Programmer Certification (OCPJP)
Doubt about IO package
vivekkumar sharma
Ranch Hand
Posts: 70
posted 17 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Hi Ranchers,
In the following code I get IOexception : Stream already closed.
It works fine if i comment line 1 below.
I am not sure how buffered writer works.
Can some one explain, does BufferedWriter open FileWriter dtream before writing or not.
TA
Vivek
import java.io.*; class TestFileWrite{ static File f = new File("Text.txt"); public static void main(String args[]) { try { FileWriter fw = new FileWriter(f,true); fw.write("bye \n Can u write a file"); fw.write('9'); fw.flush(); fw.close();// line 1 BufferedWriter bw = new BufferedWriter(fw); bw.write("hello i am using buffered write"); bw.newLine(); bw.write("OK BOSS"); bw.flush(); bw.close(); } catch(Exception e) { System.out.println(e.toString()); } } }
wise owen
Ranch Hand
Posts: 2023
posted 17 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
In
BufferedWriter.java
code, its write function does not open file.
Henry Wong
author
Posts: 23951
142
I like...
posted 17 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Furthermore, in order for the BufferedWriter to work "properly",
you should
not be writing directly to the FileWriter.
Henry
Books:
Java Threads, 3rd Edition
,
Jini in a Nutshell
, and
Java Gems (contributor)
With a little knowledge, a
cast iron skillet
is non-stick and lasts a lifetime.
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
FileIO
FileWriter vs BufferedWriter(FileWriter)
BufferedWriter, PrinterWriter etc
Not able to write the output to the file.
FileWriter
More...