List of usage examples for java.io FileReader FileReader
public FileReader(FileDescriptor fd)
From source file:MainClass.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); 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://ww w . j a va 2 s. c o m System.out.println(st.lineno() + ") " + (char) st.ttype); } } fr.close(); }
From source file:Main.java
public static void main(String[] args) throws Exception { File f = new File("hello.txt"); FileReader fr = new FileReader(f); char[] c = new char[(int) f.length()]; char[] cnew = new char[(int) f.length()]; StringBuffer sbuf = new StringBuffer(); fr.read(c, 0, (int) f.length()); int len = (int) f.length(); for (int i = 0, j = len - 1; i < len; i++, j--) { cnew[i] = c[j];/*from w w w. jav a2s .co m*/ sbuf.append(cnew[i]); } System.out.println(sbuf.toString()); fr.close(); }
From source file:Main.java
public static void main(String[] args) throws Exception { File f = new File("Main.java"); FileReader fr = new FileReader(f); char[] c = new char[(int) f.length()]; char[] cnew = new char[(int) f.length()]; StringBuffer sbuf = new StringBuffer(); fr.read(c, 0, (int) f.length()); int len = (int) f.length(); for (int i = 0, j = len - 1; i < len; i++, j--) { cnew[i] = c[j];/*from w ww.ja va 2 s. co m*/ sbuf.append(cnew[i]); } System.out.println(sbuf.toString()); fr.close(); }
From source file:MainClass.java
public static void main(String[] a) { FileReader fr;//from w w w. j a v a 2 s . com try { fr = new FileReader(new File("yourFile.txt")); BufferedReader br = new BufferedReader(fr); String line = br.readLine(); while (line != null) { System.out.println(line); line = br.readLine(); } br.close(); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:Main.java
public static void main(String[] args) throws Exception { String thisLine = null;/*from w ww . j a v a 2 s . c o m*/ BufferedReader br = new BufferedReader(new FileReader("c:/test.txt")); while ((thisLine = br.readLine()) != null) { System.out.println(thisLine); } }
From source file:Main.java
public static void main(String[] args) throws Exception { String srcFile = "test.txt"; BufferedReader br = new BufferedReader(new FileReader(srcFile)); String text = null;// www . j a v a2 s . com while ((text = br.readLine()) != null) { System.out.println(text); } br.close(); }
From source file:SourceReader.java
public static void main(String[] arguments) { try {/*from w w w . ja v a 2 s .c o m*/ FileReader file = new FileReader("SourceReader.java"); BufferedReader buff = new BufferedReader(file); boolean eof = false; while (!eof) { String line = buff.readLine(); if (line == null) eof = true; else System.out.println(line); } buff.close(); } catch (IOException e) { System.out.println("Error - " + e.toString()); } }
From source file:FileReaderWriterExample.java
public static void main(String[] args) throws Exception { Reader r = new FileReader("in.txt"); Writer w = new FileWriter("out.txt"); int c;//from w w w . j a v a 2 s . com while ((c = r.read()) != -1) { System.out.print((char) c); w.write(c); } r.close(); w.close(); }
From source file:ExtractTokens.java
public static void main(String[] args) throws Exception { FileReader fr = null;/*from w ww.java 2 s .c om*/ fr = new FileReader(args[0]); StreamTokenizer st = new StreamTokenizer(fr); while (st.nextToken() != StreamTokenizer.TT_EOF) { switch (st.ttype) { case '"': System.out.println("String = " + st.sval); break; case StreamTokenizer.TT_EOL: System.out.println("End-of-line"); break; case StreamTokenizer.TT_NUMBER: System.out.println("Number = " + st.nval); break; case StreamTokenizer.TT_WORD: System.out.println("Word = " + st.sval); break; default: System.out.println("Other = " + (char) st.ttype); } } }
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); // reads and prints data from reader System.out.println((char) lnr.read()); System.out.println((char) lnr.read()); // mark invoked at this position lnr.mark(0);/*from www.ja v a2 s . c o m*/ System.out.println("mark() invoked"); System.out.println((char) lnr.read()); System.out.println((char) lnr.read()); // if this reader supports mark() an reset() if (lnr.markSupported()) { // reset() repositioned the stream to the mark lnr.reset(); System.out.println("reset() invoked"); System.out.println((char) lnr.read()); System.out.println((char) lnr.read()); } lnr.close(); }