LineViewer.java Source code

Java tutorial

Introduction

Here is the source code for LineViewer.java

Source

import java.io.FileReader;
import java.io.LineNumberReader;

class LineViewer {
    public static void main(String[] args) throws Exception {
        LineNumberReader lnr = null;

        FileReader fr = new FileReader(args[0]);
        lnr = new LineNumberReader(fr);

        String s;
        while ((s = lnr.readLine()) != null)
            System.out.println(lnr.getLineNumber() + ": " + s);
    }
}