List of usage examples for java.io InputStreamReader InputStreamReader
public InputStreamReader(InputStream in)
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 a v a 2 s . co m*/ 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:Main.java
public static void main(String[] args) throws Exception { InputStream is = new FileInputStream("c:/test.txt"); InputStreamReader isr = new InputStreamReader(is); BufferedReader br = new BufferedReader(isr); br.close();//from w w w .j a v a 2s . c o m // creates error br.read(); }
From source file:Main.java
public static void main(String[] args) throws Exception { InputStream is = new FileInputStream("c:/test.txt"); InputStreamReader isr = new InputStreamReader(is); BufferedReader br = new BufferedReader(isr); int value = 0; while ((value = br.read()) != -1) { char c = (char) value; System.out.println(c);/*from www . java2 s.c om*/ } }
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 ww. j a va2 s .c o m*/ 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) throws Exception { InputStream is = new FileInputStream("c:/test.txt"); InputStreamReader isr = new InputStreamReader(is); BufferedReader br = new BufferedReader(isr); boolean bool = false; bool = br.markSupported();/*w w w . ja v a 2 s . co m*/ System.out.println("Buffered reader supports mark : " + bool); }
From source file:Main.java
public static void main(String[] args) throws Exception { InputStream is = new FileInputStream("c:/test.txt"); InputStreamReader isr = new InputStreamReader(is); BufferedReader br = new BufferedReader(isr); char[] cbuf = new char[is.available()]; br.read(cbuf, 2, 10);/*from w w w.ja va2 s. com*/ for (char c : cbuf) { if (c == (char) 0) { c = '*'; } // prints characters System.out.print(c); } }
From source file:Main.java
public static void main(String[] args) throws IOException { // new input stream reader is created FileInputStream fis = new FileInputStream("C:/test.txt"); InputStreamReader isr = new InputStreamReader(fis); // the name of the character encoding returned String s = isr.getEncoding(); System.out.print("Character Encoding: " + s); isr.close();/*from www. ja v a 2 s.co m*/ }
From source file:Main.java
public static void main(String[] args) throws Exception { InputStream is = new FileInputStream("c:/test.txt"); InputStreamReader isr = new InputStreamReader(is); BufferedReader br = new BufferedReader(isr); System.out.println((char) br.read()); System.out.println((char) br.read()); br.mark(26);//from www . ja va2s . c o m System.out.println("mark() invoked"); System.out.println((char) br.read()); System.out.println((char) br.read()); 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 argv[]) throws Exception { String line;//from ww w.ja v a2 s .c o m Process p = Runtime.getRuntime().exec("psql -U username -d dbname -h serverhost -f scripfile.sql"); BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream())); while ((line = input.readLine()) != null) { System.out.println(line); } input.close(); }
From source file:MainClass.java
public static void main(String[] args) throws Exception { URL u = new URL(args[0]); URLConnection uc = u.openConnection(); BufferedReader br = new BufferedReader(new InputStreamReader(uc.getInputStream())); String s = br.readLine();//from w ww .ja v a 2 s . c o m while (s != null) { System.out.println(s); s = br.readLine(); } }