Example usage for java.io FileReader FileReader

List of usage examples for java.io FileReader FileReader

Introduction

In this page you can find the example usage for java.io FileReader FileReader.

Prototype

public FileReader(FileDescriptor fd) 

Source Link

Document

Creates a new FileReader , given the FileDescriptor to read, using the platform's java.nio.charset.Charset#defaultCharset() default charset .

Usage

From source file:Main.java

public static void main(String[] args) throws Exception {
    LineNumberReader r = new LineNumberReader(new FileReader("yourFile.txt"));

    String line = null;/*  w  w w .  j  ava 2  s. c om*/

    while ((line = r.readLine()) != null) {
        System.out.println(r.getLineNumber() + ": " + line);
    }
    r.close();
}

From source file:FileReaderDemo.java

public static void main(String args[]) throws IOException {
    FileReader fr = new FileReader("FileReaderDemo.java");
    BufferedReader br = new BufferedReader(fr);
    String s;//from   www  .j  a v a  2  s  .  c  om

    while ((s = br.readLine()) != null) {
        System.out.println(s);
    }

    fr.close();
}

From source file:StreamTokenizerExample.java

public static void main(String[] args) throws Exception {

    Reader r = new FileReader("in.txt");
    StreamTokenizer st = new StreamTokenizer(r);
    while (st.nextToken() != StreamTokenizer.TT_EOF) {
        System.out.println(st.sval);
    }//from  w  w  w  . j ava 2s  . co m
    r.close();
}

From source file:Main.java

public static void main(String args[]) throws Exception {
    FileReader fr = new FileReader(args[0]);
    BufferedReader br = new BufferedReader(fr);
    StreamTokenizer st = new StreamTokenizer(br);
    st.eolIsSignificant(true);/*  w  ww  .j a  v  a  2s . c o  m*/
    int lines = 1;

    while (st.nextToken() != StreamTokenizer.TT_EOF) {
        switch (st.ttype) {
        case StreamTokenizer.TT_EOL:
            ++lines;
        }
    }
    System.out.println("There are " + lines + " lines");
    fr.close();
}

From source file:MainClass.java

public static void main(String args[]) {
    try {/*  w  ww .  ja v a 2 s.  c om*/
        FileReader fr = new FileReader(args[0]);
        BufferedReader br = new BufferedReader(fr);

        String s;
        while ((s = br.readLine()) != null)
            System.out.println(s);

        fr.close();
    } catch (Exception e) {
        System.out.println("Exception: " + e);
    }
}

From source file:LineViewer.java

public static void main(String[] args) throws Exception {
    LineNumberReader lnr = null;/*  w ww.j a  va2s.  c o m*/

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

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

From source file:Main.java

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

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

    // set current line number
    lnr.setLineNumber(100);//from ww w. j av  a 2  s .  c o  m
    System.out.println("setLineNumber(100) is invoked");

    // get current line number
    int i = lnr.getLineNumber();
    System.out.print("Current line number: " + i);
    lnr.close();
}

From source file:LineNumberIOApp.java

public static void main(String args[]) throws IOException {
    FileReader inFile = new FileReader("LineNumberIOApp.java");
    LineNumberReader inLines = new LineNumberReader(inFile);
    String inputLine;//from  w w  w.j  a v  a  2  s  .  c  o  m
    while ((inputLine = inLines.readLine()) != null) {
        System.out.println(inLines.getLineNumber() + ". " + inputLine);
    }
}

From source file:Main.java

public static void main(String args[]) throws Exception {
    FileReader fr = new FileReader(args[0]);
    BufferedReader br = new BufferedReader(fr);
    StreamTokenizer st = new StreamTokenizer(br);
    st.whitespaceChars(',', ',');
    while (st.nextToken() != StreamTokenizer.TT_EOF) {
        switch (st.ttype) {
        case StreamTokenizer.TT_WORD:
            System.out.println(st.lineno() + ") " + st.sval);
            break;
        case StreamTokenizer.TT_NUMBER:
            System.out.println(st.lineno() + ") " + st.nval);
            break;
        default:/*from   ww  w  . j  a  v a2  s.  c om*/
            System.out.println(st.lineno() + ") " + (char) st.ttype);
        }
    }
    fr.close();
}

From source file:Main.java

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

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

    // sets the current line number
    lnr.setLineNumber(100);//from   ww w . j a  v  a  2s.  com

    // get the current line number
    int i = lnr.getLineNumber();

    // print the current line number
    System.out.print("Current line number: " + i);
    lnr.close();
}