List of usage examples for java.io BufferedReader BufferedReader
public BufferedReader(Reader in)
From source file:Main.java
public static void main(String[] argv) throws Exception { File f = new File("C:\\test.txt"); FileReader fr = new FileReader(f); BufferedReader br = new BufferedReader(fr); StringBuffer sb = new StringBuffer(); String eachLine = br.readLine(); while (eachLine != null) { sb.append(eachLine);//from w w w . j a v a 2 s. c om sb.append("\n"); eachLine = br.readLine(); } System.out.println(sb.toString()); }
From source file:Main.java
public static void main(String[] args) throws Exception { String s = "from java2s.com"; StringReader sr = new StringReader(s); BufferedReader br = new BufferedReader(sr); // reads and prints BufferedReader System.out.println((char) br.read()); System.out.println((char) br.read()); // mark invoked at this position br.mark(0);//from ww w . j a v a 2 s . c om System.out.println("mark() invoked"); System.out.println((char) br.read()); System.out.println((char) br.read()); // reset() repositioned the stream to the mark br.reset(); System.out.println("reset() invoked"); System.out.println((char) br.read()); System.out.println((char) br.read()); }
From source file:Main.java
public static void main(String[] av) throws IOException { StreamTokenizer tf = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in))); int i;/* w ww. j av a 2s . com*/ while ((i = tf.nextToken()) != StreamTokenizer.TT_EOF) { switch (i) { case StreamTokenizer.TT_EOF: System.out.println("End of file"); break; case StreamTokenizer.TT_EOL: System.out.println("End of line"); break; case StreamTokenizer.TT_NUMBER: System.out.println("Number " + tf.nval); break; case StreamTokenizer.TT_WORD: System.out.println("Word, length " + tf.sval.length() + "->" + tf.sval); break; default: System.out.println("What is it? i = " + i); } } }
From source file:StreamTokenApp.java
public static void main(String args[]) throws IOException { BufferedReader inData = new BufferedReader(new InputStreamReader(System.in)); StreamTokenizer inStream = new StreamTokenizer(inData); inStream.commentChar('#'); boolean eof = false; do {//from ww w .j av a 2s.com int token = inStream.nextToken(); switch (token) { case inStream.TT_EOF: System.out.println("EOF encountered."); eof = true; break; case inStream.TT_EOL: System.out.println("EOL encountered."); break; case inStream.TT_WORD: System.out.println("Word: " + inStream.sval); break; case inStream.TT_NUMBER: System.out.println("Number: " + inStream.nval); break; default: System.out.println((char) token + " encountered."); if (token == '!') eof = true; } } while (!eof); }
From source file:MainClass.java
public static void main(String[] a) { FileReader fr;/* 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:SourceReader.java
public static void main(String[] arguments) { try {// w w w . ja v a 2 s.co 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:MainClass.java
public static void main(String[] av) throws IOException { StreamTokenizer tf = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in))); String s = null;/*from w w w .j a v a 2 s. com*/ int i; while ((i = tf.nextToken()) != StreamTokenizer.TT_EOF) { switch (i) { case StreamTokenizer.TT_EOF: System.out.println("End of file"); break; case StreamTokenizer.TT_EOL: System.out.println("End of line"); break; case StreamTokenizer.TT_NUMBER: System.out.println("Number " + tf.nval); break; case StreamTokenizer.TT_WORD: System.out.println("Word, length " + tf.sval.length() + "->" + tf.sval); break; default: System.out.println("What is it? i = " + i); } } }
From source file:Main.java
public static void main(String args[]) { try {//from w w w .j a va 2 s . c om FileReader fr = new FileReader(args[0]); BufferedReader br = new BufferedReader(fr); StreamTokenizer st = new StreamTokenizer(br); st.ordinaryChar('.'); st.wordChars('\'', '\''); while (st.nextToken() != StreamTokenizer.TT_EOL) { 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: System.out.println(st.lineno() + ") " + (char) st.ttype); } } fr.close(); } catch (Exception e) { System.out.println("Exception: " + e); } }
From source file:TabFilter.java
public static void main(String args[]) throws Exception { FileReader fr = new FileReader(args[0]); BufferedReader br = new BufferedReader(fr); FileWriter fw = new FileWriter(args[1]); BufferedWriter bw = new BufferedWriter(fw); // Convert tab to space characters String s;/*w ww. j ava2s.c o m*/ while ((s = br.readLine()) != null) { for (int i = 0; i < s.length(); i++) { char c = s.charAt(i); if (c == '\t') c = ' '; bw.write(c); } } bw.flush(); fr.close(); fw.close(); }
From source file:Main.java
public static void main(String[] argv) throws Exception { System.out.print("Enter your name: "); InputStreamReader reader = new InputStreamReader(System.in); BufferedReader in = new BufferedReader(reader); String name = in.readLine();//from w ww. j av a2 s . com System.out.println("Hello, " + name + ". Enter three ints..."); int[] values = new int[3]; double sum = 0.0; for (int i = 0; i < values.length; i++) { System.out.print("Number " + (i + 1) + ": "); String temp = in.readLine(); values[i] = Integer.parseInt(temp); sum += values[i]; } System.out.println("The average equals " + sum / values.length); }