tags:

views:

103

answers:

3

Hi,

My program has to copy file from one folder to another folder. I have used InputStream and OutputStream to do he same. The file size is about 5GB. what are all the possible exception may occur during this process and how?. As i need mention the same in unit testcase document...Please help.

+3  A: 

Look at the java docs for the methods you are using. Any Sun Java docs will mention exceptions that can be thrown by methods.

I am guessing FileNotFoundException, NullPointerException, IOException.

willcodejavaforfood
IOException is the superclass of all IO exceptions (i.e. FileNotFoundException is a subclass of IOException) so you could probably just put that. NullPointerException is a runtime exception so probably not necessary to put.
Phill Sacre
You could but usually you want to be as specific as possible since you might want to take different actions based on the exception type.Regarding NPE, any exception thrown must be documented.
willcodejavaforfood
+1  A: 

Also consider using NIO for file copying, as it is likely that you'll get better performance which should be noticable with such a large file:

Take a look at this post from JavaLobby, which shows a static file copy method using java.io.FileChannels to do the grunt work.

David Grant
A: 

As a general rule, checked exceptions don't pop out of thin air. They are explicitly declared to be thrown by the methods you use (check the Java API). A good IDE (e.g. NetBeans) would even automatically prompt you to catch or declare these exceptions whenever you encounter them. Besides, you wouldn't even be able to compile your code if you didn't handle these exceptions. You have been documenting all these exceptions with Javadoc right? =)

Zach Scrivena