Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

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

public class Main {
    public static void main(String[] args) throws IOException {

        String str;
        // create new reader
        FileReader fr = new FileReader("C:/test.txt");
        LineNumberReader lnr = new LineNumberReader(fr);

        // read lines till the end of the stream
        while ((str = lnr.readLine()) != null) {
            int i = lnr.getLineNumber();
            System.out.print("(" + i + ")");

            // prints string
            System.out.println(str);
        }
        lnr.close();
    }
}