When file not found Exception occured i want to set the string Errortext = file not found

When file not found Exception occured i want to set the string ErrorText = File Not Found
LVL 9
Manikandan ThiagarajanSenior consultantAsked:
Who is Participating?
 
stephano12Connect With a Mentor Commented:
you could use this example:
       
   public static void main(String[] args) throws FileNotFoundException {
		File f = new File("example.txt");
		try {
			BufferedReader bf = new BufferedReader(new FileReader(f));
		} catch (FileNotFoundException e) {
			throw new FileNotFoundException("file not found");
		}
	}

Open in new window

public static void main(String[] args) throws FileNotFoundException {
		File f = new File("example.txt");
		try {
			BufferedReader bf = new BufferedReader(new FileReader(f));
		} catch (FileNotFoundException e) {
			throw new FileNotFoundException("file not found");
		}
		
	}

Open in new window

0
 
ksivananthCommented:
try{
//actual code here
}catch( FileNotFoundException fnfe ){
  errorText = "File not found" ;
}
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.