Results 1 to 14 of 14
Thread: Copying Files
- 06-11-2010, 02:41 AM #1
Member
- Join Date
- Jun 2010
- Posts
- 5
- Rep Power
- 0
Copying Files
Hi All,
Im looking for some assistance in writing a basic program which will copy the contents of a source file to a destination file. The program should prompt the user for both the source and destination file names as well.
I know this should be simple but evidently Im not very good with Java.
PLEASE HELP!!
- 06-11-2010, 02:52 AM #2
Senior Member
- Join Date
- Feb 2010
- Location
- Waterford, Ireland
- Posts
- 748
- Rep Power
- 4
Are source file and destination file on the same computer?
- 06-11-2010, 04:20 AM #3
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Of course we can help you to solve this, but not in this. I don't think anyone wants to write code for you. If you really want to do that then paid and hire someone to do it.
Show your effort, what you've done so far. Looking at that we can guide you. That's the idea about a forum.
As a hint read Java IO API, you can find useful stuff.
- 06-11-2010, 07:29 PM #4
Member
- Join Date
- Jun 2010
- Posts
- 5
- Rep Power
- 0
Yes the source and destination files are both on the same computer. I have this code below:
I keep receiving this error when running the program:Java Code:import java.io.File; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class copy { public static void main(String[] args) throws IOException { File inputFile = new File("in.txt"); File outputFile = new File("out.txt"); FileReader in = new FileReader(inputFile); FileWriter out = new FileWriter(outputFile); int c; while ((c = in.read()) != -1) out.write(c); in.close(); out.close(); } }
Exception in thread "main" java.io.FileNotFoundException: in.txt (The system cannot find the file specified)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(FileInputStream.jav a:106)
at java.io.FileReader.<init>(FileReader.java:55)
at copy.main(copy.java:11)
I know the file is in the same directory so Im not quite sure whats happening..Last edited by Eranga; 06-12-2010 at 03:03 AM. Reason: code tags added
- 06-11-2010, 07:54 PM #5
Senior Member
- Join Date
- Feb 2009
- Posts
- 303
- Rep Power
- 5
Try passing in the full path to "in.txt" to the File constructor
- 06-11-2010, 08:00 PM #6
Where is the file? Where is your program? Are they in the same folder?(The system cannot find the file specified)
- 06-11-2010, 10:34 PM #7
Member
- Join Date
- Jun 2010
- Posts
- 5
- Rep Power
- 0
Yes they are both in the same folder..
- 06-11-2010, 10:42 PM #8
Can you open a terminal/command prompt window, go the folder with the files, display the files in that folder, execute the java command with your program and then copy and paste everything from the window to this forum?
- 06-11-2010, 10:47 PM #9
Member
- Join Date
- Jun 2010
- Posts
- 5
- Rep Power
- 0
Well when I opened the command prompt and displayed the directory listing of the folder with my files I noticed that the file was named "in.txt.txt" Not sure how that happened but I renamed it to "in.txt" and it works. :)
Thanks for the help!!
- 06-11-2010, 10:49 PM #10
in.txt.txt - One of the gotchas from Microsoft's attempt to hide details from users.
Go into the setup for Windows Explorer and change the setting to display the extensions of files.
- 06-11-2010, 10:52 PM #11
Member
- Join Date
- Jun 2010
- Posts
- 5
- Rep Power
- 0
Gotta love windows. :) thanks again!
- 06-12-2010, 03:07 AM #12
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
- 06-12-2010, 03:12 AM #13
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
- 06-12-2010, 03:15 AM #14
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Similar Threads
-
Not Copying Libraries!?!
By Atriamax in forum NetBeansReplies: 0Last Post: 10-13-2009, 07:56 AM -
problems copying a file
By atom86 in forum Advanced JavaReplies: 16Last Post: 10-01-2009, 02:40 PM -
Copying ArrayList into an Array
By Manfizy in forum New To JavaReplies: 6Last Post: 07-16-2009, 07:03 AM -
Copying a derectory
By linux1man in forum New To JavaReplies: 10Last Post: 01-15-2009, 07:16 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks