Results 1 to 3 of 3
- 04-15-2009, 02:12 AM #1
Transferring a .txt file from 1 location to another
I have the code for creating a folder in a set location
Now I am trying to work out the easiest way on the click of a second button to copy a .txt file from 1 location on my c drive to the folder that the previous code created, I have the path etc just cant seem to get the syntax rightJava Code:File f = new File("path in here"); f.mkdir();
Thanks in advance
- 04-15-2009, 04:55 AM #2
Move a file - delete original - not what i want
Ok I now am able to transfer the .txt file from 1 location to another but it deletes the original which I dont want I just want to copy it
Anyone help?Java Code:File a = new File ("path......"); a.renameTo(new File("path....\\filename.txt"));
Thanks
- 04-15-2009, 05:22 AM #3
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
What you have to do is,
1. Create two new file instance, one for the source and one for the destination.
The InputStream instance for input and OutputStream for output file object.Java Code:File sou = new File(souFile); File des = new File(desFile);
Finally create a byte buffer to read the file.Java Code:InputStream inStr = new FileInputStream(sou); OutputStream outStr = new FileOutputStream(des);
Hope this is clear, If not let me know.Java Code:byte[] readBuf = new byte[2048]; // Depends on your file size outStr.write(readBuf, 0, #of_bytes_reads);
Similar Threads
-
Netbeans errors when transferring file
By dbashby in forum New To JavaReplies: 7Last Post: 04-15-2009, 03:41 PM -
Java logging - log file location for FileHandler
By kfir.wolfson@gmail.com in forum Advanced JavaReplies: 2Last Post: 03-24-2009, 08:22 AM -
weird location of ovals
By diggitydoggz in forum New To JavaReplies: 6Last Post: 12-24-2008, 12:25 AM -
Transferring Over Network
By qwerty in forum Advanced JavaReplies: 2Last Post: 08-01-2008, 01:40 PM -
how to get the location of some button
By mary in forum Java 2DReplies: 2Last Post: 08-05-2007, 04:02 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks