• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

I/O filestreams

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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:
 
Ranch Hand
Posts: 1365
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Could you hold this kitten for a sec? I need to adjust this tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic