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 5 of 5

Thread: File and PrintWriter objects

  1. #1
    Junior Member
    Join Date
    Jun 2014
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default File and PrintWriter objects

    If I am using the File object to read a file and PrintWriter object to write to a separate file, can I use them under one method. Or is the File one method and the PrintWriter another method?


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,334
    Thanks
    181
    Thanked 830 Times in 773 Posts
    Blog Entries
    5

    Default Re: File and PrintWriter objects

    Or is the File one method and the PrintWriter another method?
    I don't think I understand your question: they are not methods, they are classes.
    File (Java Platform SE 7 )
    PrintWriter (Java Platform SE 7 )

  3. #3
    Junior Member
    Join Date
    Jun 2014
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: File and PrintWriter objects

    Ok,
    So I want to create a method to read data from a file. I also want to print data to a separate file. So, can I create one method to do both tasks using the File class and the PrintWriter class? I hope that makes more sense.

    thank you

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    21,040
    Thanks
    52
    Thanked 2,280 Times in 2,251 Posts

    Default Re: File and PrintWriter objects

    can I create one method to do both tasks using the File class and the PrintWriter class?
    Your one method can call methods in other classes to do the reading and writing.
    BTW The File class does not have methods for reading the contents of a file.
    The Scanner class has several methods for reading the contents of a file.
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Junior Member
    Join Date
    Jun 2014
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: File and PrintWriter objects

    Yes, you are right the File class will open the file. Got it. Thanks for the insight. I think I got it now.

    thanks again

Similar Threads

  1. [SOLVED] PrintWriter out problem
    By Randor in forum Java Networking
    Replies: 1
    Last Post: November 27th, 2012, 08:55 AM
  2. PrintWriter: passing File reference vs String
    By kahwa in forum File I/O & Other I/O Streams
    Replies: 1
    Last Post: April 12th, 2012, 12:56 AM
  3. [SOLVED] Printwriter class: displaying File contents to screen with included formatting?
    By mwebb in forum File I/O & Other I/O Streams
    Replies: 10
    Last Post: November 25th, 2011, 10:38 AM
  4. HELP with sending data within text file to client with printwriter
    By dannyyy in forum What's Wrong With My Code?
    Replies: 1
    Last Post: April 24th, 2011, 02:42 PM
  5. Problems with PrintWriter
    By dbridle in forum What's Wrong With My Code?
    Replies: 10
    Last Post: October 29th, 2010, 03:51 PM