Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 01-22-2008, 05:02 PM
Member
 
Join Date: Nov 2007
Posts: 50
sireesha is on a distinguished road
IOStreams
Hi all,
please see below code...
Code:
import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class ChracterStreams { public static void main(String[] args) throws IOException { FileReader in=null; FileWriter out=null; try { in=new FileReader("E:/Documents and Settings/Naresh/Desktop/java/abc.txt"); out=new FileWriter("E:/Documents and Settings/Naresh/Desktop/java/xyz.txt"); int c; while((c=in.read())!=-1) out.write(c); } finally { if(in!=null) in.close(); if(out!=null) out.close(); } } }
It successfully writes data from abc.txt to xyz.txt.
but it overwrites data in xyz.txt.
I just want to append new data in abc.txt to the data in xyz.txt.
now what i have to do ?
anyone please tell me....
Thankq very much.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 01-22-2008, 07:33 PM
Member
 
Join Date: Jan 2008
Posts: 6
XiaoXiao is on a distinguished road
Just use different constructor
FileWriter has an other constructor where you can specify whether to append or overwrite.
use

out=new FileWriter("E:/Documents and Settings/Naresh/Desktop/java/xyz.txt",true);
the boolean true will set that to append mode.
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 01-22-2008, 10:57 PM
Member
 
Join Date: Nov 2007
Posts: 50
sireesha is on a distinguished road
thankq very much
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 01-23-2008, 12:46 AM
gibsonrocker800's Avatar
Senior Member
 
Join Date: Nov 2007
Location: New York
Posts: 143
gibsonrocker800 is on a distinguished road
Send a message via AIM to gibsonrocker800
Ahh thanks for that information XiaoXiao. I never knew that. That will come in handy!!! =]
__________________
//Haha javac, can't see me now, can ya?
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 01-23-2008, 07:46 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 4,412
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
Look at the documentation. Here is a link.
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Has someone helped you? Then you can
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.

Want to make your IDE the best?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +3. The time now is 01:21 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org