Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

I/O filestreams  RSS feed

 
atif abbas
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HI..
I have an excercise where i have to Write a program that copies a text file onto another file.
Program accepts a command line:
java copy original file destination file.
program checks that both file names exist or throws an exception. It then copies the file as per command line arguments.
here is my source code so far. and would like someone to check it for me and correct me please..
The file compiles.

[ May 23, 2002: Message edited by: Dirk Schreckmann ]
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, have you tried to use it? It looks like it will copy fine, but only with file names sri.txt and file.txt. You'll want to read the command line to get file names from the user, right?
Also:

Code like this is evil and should never be written unless you're sure you know why the exception occurred, and that it should be completely ignored. That's rarely the case - certainly not here. If something goes wrong here, your program will do nothing, with no information at all about what went wrong. If you're not sure what to do with an exception, at the very least print a stack trace:
 
David Weitzman
Ranch Hand
Posts: 1365
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Even at that, "catch(IOException e) { e.printStackTrace();}" isn't really necessary. If you're not going to do anything to handle an Exception it's usually best to just declare that your function 'throws IOException' and let the VM do the printing.
atif, I'm a bit curious as to why you chose to embody your logic in a constructor. Is that just the way you've learned to do things?
[ May 24, 2002: Message edited by: David Weitzman ]
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!