Hi,
I would like to know which of the following is efficient to handle:
First way:
----------
InputStreamReader reader = null;
try {
reader = new InputStreamReader(new FileInputStream(file);
} catch (FileNotFoundException ex) {
InputStream is = ClassLoader.getSystemAsResource
(file.getPath());
reader = new InputStreamReader(is);
}
Here file is an instance of File class. The path of the file
may come in the form of directory in user's directory
"D:\JDK1.3" or in the form of "com/borland/xxx/myFile.txt"
The latter form, which I know of is for getting a file in a
Jar file.
Second way:
-----------
InputStreamReader reader = null;
if (file.isFile())
{
reader = new InputStreamReader(new FileInputStream(file));
}
else
{
InputStream is = ClassLoader.getSystemAsResource(
file.getPath());
reader = new InputStreamReader(is);
}
Even the second way will throws a FileNotFoundException which
which must be caught, I just pass up to the calling method. I
wanted to look for files that may reside either in user's
working directory or in the jar files. Which is the correct
form in handling this case?
Thanks in advance,