Guest User

Untitled

a guest
Jun 18th, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. import java.io.*;
  2. import java.util.Scanner;
  3.  
  4. public class readStuff {
  5.  
  6. private static Scanner reader = new Scanner(System.in);
  7.  
  8.  
  9. /*
  10. returns 1 if all went well, 0 when file is not found and other errors
  11. go below zero.
  12.  
  13. 1: All well.
  14. 0: No file.
  15. -1: File was empty.
  16.  
  17.  
  18. FIXME
  19. Do this properly.
  20. */
  21. public static int readFile(String fileName) throws FileNotFoundException {
  22. File fileObject = new File(fileName);
  23. if (!fileObject.exists()) {
  24. System.out.println("The file "+ fileName +" was not found!");
  25. return 0; // Stop the Party Van!
  26. }
  27.  
  28. Scanner inputFile = new Scanner(fileObject);
  29. while (inputFile.hasNextLine()) {
  30. String line = inputFile.nextLine();
  31. System.out.println(line);
  32. }
  33. return 1; //All done folks!
  34. }
  35.  
  36. public static void main(String[] args) throws FileNotFoundException { //main
  37. String file;
  38. System.out.println("\t.:Test Java App:.");
  39. System.out.print("Input File:");
  40. file = reader.nextLine();
  41. readFile(file);
  42. System.out.println("Siinä meni!");
  43. }
  44.  
  45. }
Add Comment
Please, Sign In to add comment