Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
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 08-01-2007, 04:50 AM
Member
 
Join Date: Jul 2007
Posts: 18
jason27131 is on a distinguished road
how to edit lines.
right now, im trying to edit the text file. however, all it does is overwrite over the original file. I want the string i add to be added to the original file. Is there someway i can do this?

For example, the original text says "hi". I want to add "how are you to it", so it would say "hi. how are you."


Codesimilar to before)

import java.io.*;

public class FileAccess {

public void displayFile(String f) throws IOException {
FileReader fr = new FileReader(f);
BufferedReader br = new BufferedReader(fr);


f = br.readLine();
while (f != null) {
System.out.println(f);
f = br.readLine();
}
br.close();
fr.close();
}

public void writeToFile(String outfile, String s) throws IOException {
FileOutputStream fs = new FileOutputStream(outfile);
PrintStream p = new PrintStream(fs);
p.println(s);
p.close();
fs.close();
}
}
thanks again.
ps. srry for all these questions
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 08-01-2007, 05:41 AM
Senior Member
 
Join Date: Jul 2007
Posts: 134
brianhks will become famous soon enough
Change your code to this
Code:
FileOutputStream fs = new FileOutputStream(outfile, true);
The "true" tells it to append to the file instead of overwriting it.
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


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to get the count of all the lines in a file Java Tip java.io 0 04-06-2008 08:45 PM
how can we remove blank lines from a .txt Camden New To Java 1 03-12-2008 07:02 AM
Can't edit JTextField after modal dialog JavaNerd Java Applets 0 02-07-2008 10:11 PM
How To Edit/Add JSP Pages in NetBeans IDE JavaForums NetBeans 0 07-31-2007 12:13 AM
Doubt in edit and delete methods ai_2007 Advanced Java 3 07-01-2007 12:40 PM


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


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