Results 1 to 7 of 7
Thread: Storing Files
- 05-07-2009, 05:22 AM #1
Member
- Join Date
- May 2008
- Posts
- 7
- Rep Power
- 0
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.
- 05-07-2009, 05:25 AM #2
Don't forget to mark threads as [SOLVED] and give reps to helpful posts.
How To Ask Questions The Smart Way
- 05-07-2009, 05:50 AM #3
Member
- Join Date
- Mar 2009
- Posts
- 52
- Rep Power
- 0
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.
- 05-07-2009, 02:24 PM #4
Member
- Join Date
- May 2008
- Posts
- 7
- Rep Power
- 0
"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.
- 05-07-2009, 02:26 PM #5
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
- 05-07-2009, 02:33 PM #6
Member
- Join Date
- May 2008
- Posts
- 7
- Rep Power
- 0
"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...
- 05-07-2009, 02:37 PM #7
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
-
storing strings into an array
By anthonym2121 in forum New To JavaReplies: 2Last Post: 04-04-2009, 07:32 AM -
storing information
By bsebal28 in forum New To JavaReplies: 3Last Post: 03-26-2009, 08:10 AM -
Storing and Retrieveing Data Using XStream & xml Files
By geeeeky.girl in forum New To JavaReplies: 0Last Post: 01-04-2009, 10:24 PM -
Help in storing Information
By care in forum New To JavaReplies: 1Last Post: 12-01-2008, 09:16 PM -
Storing Data
By Khorod in forum New To JavaReplies: 1Last Post: 08-03-2007, 05:48 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks