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: How do I copy a simple text-file to a new text-file?

  1. #1
    Junior Member
    Join Date
    Dec 2012
    Location
    Oslo, Norway
    Posts
    1
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default How do I copy a simple text-file to a new text-file?

    Hi.

    I'm trying to copy a simple text-file, to a new text-file, using BufferedReader and PrintWriter.

    Can anyone please show me the correct way to use these methods together, and how to run throgh the file correctly?

    Can I use both FileWriter and BefferedReader in the same try block? If so, how do I handle Exceptions?

    Thank you in advance!


  2. #2
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default Re: How do I copy a simple text-file to a new text-file?

    Any of the popular search engines will provide a wealth of code examples. What did you find?

    Again for proper use of the methods you should get in the habit of consulting the documentation and a search engine first.

    Try blocks can have multiple catch blocks.

    Try {
       somethingRisky();
       doSomethingElseRisky();
       doTheThirdRiskyActivity();
    }
    catch(theFirstRisk tfr) {
       reportOops();
    }
    catch(theSecondRisk tsr) {
       reportOops();
    }
    catch(theThirdRisk ttr) {
       reportOops();
    }

    Also see the try-with-resources and surrounding pages.

  3. The Following User Says Thank You to jps For This Useful Post:

    get703 (December 6th, 2012)

Similar Threads

  1. Beginner I/O Help: Writing To a Text File At the End of Existing Lines of Text
    By BloomingNutria in forum File I/O & Other I/O Streams
    Replies: 1
    Last Post: February 28th, 2012, 03:03 PM
  2. simple program for reading text file
    By johnpipes in forum What's Wrong With My Code?
    Replies: 5
    Last Post: December 21st, 2011, 05:55 PM
  3. Text file to text area and Radiobuttons?
    By donaldmax in forum What's Wrong With My Code?
    Replies: 9
    Last Post: May 27th, 2011, 05:45 AM
  4. Replies: 8
    Last Post: March 25th, 2011, 03:34 PM
  5. java program to copy a text file to onother text file
    By francoc in forum File I/O & Other I/O Streams
    Replies: 3
    Last Post: April 23rd, 2010, 04:10 PM