Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;

public class Main {
    private static void readFile(String fileName) throws Exception {
        File file = new File(fileName);
        FileReader reader = new FileReader(file);
        BufferedReader in = new BufferedReader(reader);
        String string;
        while ((string = in.readLine()) != null) {
            System.out.println(string);
        }
        in.close();
    }

    public static void main(String[] args) throws Exception {
        if (args.length != 1) {
            System.err.println("usage: java TextReader " + "file location");
            System.exit(0);
        }
        readFile(args[0]);
    }
}