P
Prabh
Hello all,
I'm trying to access and describe a file and print out some messaging
if the file's not found.
Can anyone tell me what I'm doing wrong with try/catch?
I run into : "
exception java.io.FileNotFoundException is never thrown in body of
corresponding try statement
catch ( FileNotFoundException fne ) {
^
Should I throw my own exception?
===================================================================================
import java.io.* ;
public class findFile {
public static void main ( String args[] ) {
try {
File file = new File("myFile.txt") ;
long getLength = file.length() ;
System.out.println("Length is: " + getLength ) ;
}
catch ( FileNotFoundException fne ) {
System.out.println("Cant Access file!!") ;
fne.printStackTrace() ;
}
}
}
===================================================================================
I tried removing the try/catch, but it gives a misleading answer when
the file's not found, "Length is: 0".
I know, "0" mostly means a non-existent file, but I want put it in
plain English for the user.
I have to catch this thing.
Thanks for any pointers,
Prabh
I'm trying to access and describe a file and print out some messaging
if the file's not found.
Can anyone tell me what I'm doing wrong with try/catch?
I run into : "
exception java.io.FileNotFoundException is never thrown in body of
corresponding try statement
catch ( FileNotFoundException fne ) {
^
Should I throw my own exception?
===================================================================================
import java.io.* ;
public class findFile {
public static void main ( String args[] ) {
try {
File file = new File("myFile.txt") ;
long getLength = file.length() ;
System.out.println("Length is: " + getLength ) ;
}
catch ( FileNotFoundException fne ) {
System.out.println("Cant Access file!!") ;
fne.printStackTrace() ;
}
}
}
===================================================================================
I tried removing the try/catch, but it gives a misleading answer when
the file's not found, "Length is: 0".
I know, "0" mostly means a non-existent file, but I want put it in
plain English for the user.
I have to catch this thing.
Thanks for any pointers,
Prabh