Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.*;
- import java.util.Scanner;
- public class readStuff {
- private static Scanner reader = new Scanner(System.in);
- /*
- returns 1 if all went well, 0 when file is not found and other errors
- go below zero.
- 1: All well.
- 0: No file.
- -1: File was empty.
- FIXME
- Do this properly.
- */
- public static int readFile(String fileName) throws FileNotFoundException {
- File fileObject = new File(fileName);
- if (!fileObject.exists()) {
- System.out.println("The file "+ fileName +" was not found!");
- return 0; // Stop the Party Van!
- }
- Scanner inputFile = new Scanner(fileObject);
- while (inputFile.hasNextLine()) {
- String line = inputFile.nextLine();
- System.out.println(line);
- }
- return 1; //All done folks!
- }
- public static void main(String[] args) throws FileNotFoundException { //main
- String file;
- System.out.println("\t.:Test Java App:.");
- System.out.print("Input File:");
- file = reader.nextLine();
- readFile(file);
- System.out.println("Siinä meni!");
- }
- }
Add Comment
Please, Sign In to add comment