public class Question11
1: //Question11.java
2:
3: import java.io.File;
4: import java.util.Scanner;
5: public class Question11
6: {
7: public static void main(String[] args)
8: {
9: System.out.print("Enter a file name and I will ");
10: System.out.println("tell you whether it exists.");
11: Scanner keyboard = new Scanner(System.in);
12: String name = keyboard.next();
13: File fileObject = new File(name);
14:
15: if (fileObject.exists())
16: {
17: System.out.println("I found the file " + name);
18: System.out.println("Delete the file?");
19: String ans = keyboard.next();
20: if (ans.equalsIgnoreCase("yes"))
21: {
22: System.out.println("If you delete the file " + name);
23: System.out.println("all data in the file will be lost.");
24: System.out.println("Delete?");
25: ans = keyboard.next();
26: if (ans.equalsIgnoreCase("yes"))
27: {
28: if (fileObject.delete())
29: System.out.println("File deleted.");
30: else
31: System.out.println("CanÕt delete.");
32: }
33: else
34: System.out.println("File not deleted.");
35: }
36: else
37: System.out.println("File not deleted.");
38: }
39: else
40: System.out.println("I cannot find " + name);
41: }
42: }