Results 1 to 7 of 7

Thread: Storing Files

  1. #1
    superwaxer is offline Member
    Join Date
    May 2008
    Posts
    7
    Rep Power
    0

    Default Storing Files

    Hi all,

    Im attempting to upload a file and store a copy of it in a different directory. I tried to do this by creating a new file in the target directory and then renaming the uploaded file to that file. This works fine except it removes the original file in the original directory. Here's a piece of my code:

    File newFile = new File(jTextField1.getText());
    if (newFile.exists()) {
    java.io.File tempFile = new java.io.File("Dictionaries/" + jTextField2.getText() + ".txt");
    newFile.renameTo(tempFile);
    jLabel3.setText("File added successfully");
    }else{
    jLabel3.setText("File does not exist");
    }

    What I would like to know is how can I, instead of moving the original file to the new directory, move a copy of it so that the original file remains in the original directory? Any help is appreciated.

  2. #2
    OrangeDog's Avatar
    OrangeDog is offline Senior Member
    Join Date
    Jan 2009
    Location
    Cambridge, UK
    Posts
    838
    Rep Power
    6

    Default

    Don't forget to mark threads as [SOLVED] and give reps to helpful posts.
    How To Ask Questions The Smart Way

  3. #3
    ron87 is offline Member
    Join Date
    Mar 2009
    Posts
    52
    Rep Power
    0

    Default

    i think u need to write file copy logic if you want to copy it..
    using fileInputStream read the contents of the file and write them into a new file.

  4. #4
    superwaxer is offline Member
    Join Date
    May 2008
    Posts
    7
    Rep Power
    0

    Default

    "Let me google that for you"

    Why thank you hotdog! No one ever took the time to teach me how to type a google search! Man, you really do learn a lot from this forum! O and thanks ron87, your appreciation for my common sense is much appreciated.

  5. #5
    OrangeDog's Avatar
    OrangeDog is offline Senior Member
    Join Date
    Jan 2009
    Location
    Cambridge, UK
    Posts
    838
    Rep Power
    6

    Default

    Yet you failed to find a single one of those solutions before posting here.
    Don't forget to mark threads as [SOLVED] and give reps to helpful posts.
    How To Ask Questions The Smart Way

  6. #6
    superwaxer is offline Member
    Join Date
    May 2008
    Posts
    7
    Rep Power
    0

    Default

    "Yet you failed to find a single one of those solutions before posting here."

    Yeah I guess I wasnt smart enough to know what I was looking for at that stage. But I really do appreciate your kindness towards other members hotdog. I wont post on this forum again as I asked for an honest piece of advice, not a sarcastic reply where someone tries to make me feel like a complete idiot. I like forums as they are there to teach you something, but unfortunately some just dont get it. What a shame...

  7. #7
    OrangeDog's Avatar
    OrangeDog is offline Senior Member
    Join Date
    Jan 2009
    Location
    Cambridge, UK
    Posts
    838
    Rep Power
    6

    Default

    Treat this a learning experience. Both in how to construct suitable search-engine queries, and how volunteers who answer questions on forums dislike having to constantly repeat themselves. I like to teach people how to be self-sufficient.
    Don't forget to mark threads as [SOLVED] and give reps to helpful posts.
    How To Ask Questions The Smart Way

Similar Threads

  1. storing strings into an array
    By anthonym2121 in forum New To Java
    Replies: 2
    Last Post: 04-04-2009, 08:32 AM
  2. storing information
    By bsebal28 in forum New To Java
    Replies: 3
    Last Post: 03-26-2009, 09:10 AM
  3. Storing and Retrieveing Data Using XStream & xml Files
    By geeeeky.girl in forum New To Java
    Replies: 0
    Last Post: 01-04-2009, 11:24 PM
  4. Help in storing Information
    By care in forum New To Java
    Replies: 1
    Last Post: 12-01-2008, 10:16 PM
  5. Storing Data
    By Khorod in forum New To Java
    Replies: 1
    Last Post: 08-03-2007, 06:48 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •