fork download
  1.  
  2. import java.util.Scanner;
  3. import java.io.*;
  4.  
  5. public class FileName
  6. {
  7. public static void main(String[] arg) throws IOException
  8. {
  9. String filename;
  10. int x;
  11. int z = 0; //Counts numbers less than input
  12. Scanner input = new Scanner(System.in);
  13.  
  14. System.out.print("\nEnter the file name: "); //Prompt user for file name
  15. filename = input.nextLine();
  16.  
  17. File file = new File(filename); //Create file
  18.  
  19.  
  20. if(!file.exists()) //Checks for file's existance
  21. {
  22. System.out.println("\n" + filename + "does not exist.");
  23. System.exit(0);
  24. }
  25.  
  26. else if (file.exists())
  27. {
  28. System.out.println("\n" + filename + " was found.");
  29. }
  30.  
  31. Scanner inputFile = new Scanner(file); //Open file
  32.  
  33. System.out.print("\nEnter an integer"); //prompt user for specified integer
  34. x = input.nextInt();
  35.  
  36. while (inputFile.hasNext()) //Read until the end of the file
  37. {
  38. int y = inputFile.nextInt(); //Read a line from the file
  39. System.out.println(y);
  40.  
  41. if (x > y)
  42. {
  43. z = z+1;
  44. }
  45.  
  46. else
  47. {
  48. continue;
  49. }
  50. }
  51.  
  52. System.out.println("\nThere are " + z + " numbers below " + x);
  53.  
  54. inputFile.close(); //Close the file
  55. }
  56. }
  57.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:5: error: class FileName is public, should be declared in a file named FileName.java
public class FileName
       ^
1 error
stdout
Standard output is empty