Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Help please - urgent (Project due and not done) - Easy answer

  1. #1
    Junior Member
    Join Date
    Nov 2010
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Help please - urgent (Project due and not done) - Easy answer

    Can somebody please teach me how to edit existent files with java? I just need basics like how do you add lines to a file, search lines in a file and delete lines in a file.

    If you guys give me a guide i will waste a lot of time i don't have trying to understand it because i am terrible at understanding guides so if you please want to help me just write me out few lines of codes and say how it works.

    -thank you

    this is what i use to create new files.

    File userFileLog = new File(userFileId);
    		if(!userFileLog.exists())
    		{
    			PrintWriter output2 = new PrintWriter(userFileLog);
    			output2.print("Text");
    			output2.close();
    		}

    so what do i do if the file does exist? I need to add some lines and remove some from that file.
    Last edited by Bagzli; March 2nd, 2011 at 05:54 PM.


  2. #2
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 294 Times in 227 Posts
    Blog Entries
    4

    Default Re: Help please - urgent (Project due and not done) - Easy answer

    If the file exists, Java will automatically overwrite it.

    If you wish to add lines to an existing file, you could always read it in and then write it back out again.
    You can do a similar thing for searching the file. Read it in line by line and search the String for a word or phrase.

    See:

    http://www.javaprogrammingforums.com...ner-class.html

    http://www.javaprogrammingforums.com...redreader.html
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

Similar Threads

  1. Does anyone have answer of this Assignment??
    By lulzimfazlija in forum Java Theory & Questions
    Replies: 3
    Last Post: January 21st, 2011, 05:02 AM
  2. Need urgent help with my project..
    By secretsau in forum What's Wrong With My Code?
    Replies: 1
    Last Post: November 27th, 2010, 09:43 AM
  3. [SOLVED] Begginer Question please help ASAP! (Easy to Answer)
    By Bagzli in forum What's Wrong With My Code?
    Replies: 2
    Last Post: November 11th, 2010, 10:00 PM
  4. Replies: 5
    Last Post: August 5th, 2010, 09:16 PM