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

Thread: Reading and writing file

  1. #1
    Junior Member
    Join Date
    May 2014
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Reading and writing file

    Helo! I need a simple java code that ask the user to select a jar file by navigating through hard drive and then i want that selected file to store /write in a particular destination(ie my own folder)..Thanks


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Reading and writing file

    The JFileChooser class is useful for allowing a user to choose a file to open.

    For reading from and writing to a file, the RandomAccessFile is useful.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    May 2014
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Reading and writing file

    ok ...JFilechooser will help me to just point to a file then is there a way to just copy that file to particular destination without reading or writing...ie i need a simplest way of copying that file to some other destination,,,

  4. #4
    Senior Member
    Join Date
    Jul 2013
    Location
    Europe
    Posts
    666
    Thanks
    0
    Thanked 121 Times in 105 Posts

    Default Re: Reading and writing file

    The easiest way is to simply copy the contents yourself.
    Create a new File object at the target destination, open the new file object, write the contents of the old file into the new file, and then remove the old file.

  5. #5
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Reading and writing file

    copy that file to particular destination without reading or writing.
    That sounds like magic: no reading or writing.
    To copy a file, the source must be read and the new file written.
    If you don't understand my answer, don't ignore it, ask a question.

  6. #6
    Junior Member
    Join Date
    May 2014
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Reading and writing file

    Thanx! alot brother

  7. #7
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Reading and writing file

    Some OSs have utilities to copy files. Perhaps you could execute one of them to do the copy.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Reading from a Text file & writing to Excel spreadsheets
    By javanooby in forum File I/O & Other I/O Streams
    Replies: 2
    Last Post: May 14th, 2012, 12:41 PM
  2. File I/O reading from text and writing to another, PLEASE ADVISE! basic
    By Loki617 in forum File I/O & Other I/O Streams
    Replies: 14
    Last Post: April 16th, 2012, 01:29 PM
  3. Trouble with writing/reading array to/from file
    By MaximusPrime in forum What's Wrong With My Code?
    Replies: 2
    Last Post: March 4th, 2012, 08:41 PM
  4. file reading & writing
    By macko in forum What's Wrong With My Code?
    Replies: 7
    Last Post: May 12th, 2011, 08:54 AM
  5. Reading a writing binary file
    By stu1811 in forum File I/O & Other I/O Streams
    Replies: 1
    Last Post: July 30th, 2010, 12:58 PM

Tags for this Thread