50 likes | 160 Views
Readers. a means of reading text. What are readers?. Inputs a stream Outputs a String Unicode is produced from ASCII input Manage the translation from non ASCII input ASCII – American Standard Code for Information Interchange EBCDIC – Extended Binary Coded Decimal Interchange Code.
E N D
Readers a means of reading text
What are readers? • Inputs a stream • Outputs a String • Unicode is produced from ASCII input • Manage the translation from non ASCII input • ASCII – American Standard Code for Information Interchange • EBCDIC – Extended Binary Coded Decimal Interchange Code.
How do I build a reader? BufferReader br = new BufferedReader(new InputStreamReader(new FileInputStream(f))); .... while ((String s = br.readLine()) != null) { processLine(s); }
Simple encryption try { FileReader fr = new FileReader("input.txt"); int c = reader.read(); while(c != -1) { char newC = encrypt((char) c); System.out.print(newC); c = reader.read(); } reader.close(); }......add a catch clause......
BufferedReader: one line at a time • Analogously, you may want to read in a line at a time • Use BufferedReader • public BufferedReader(Reader in) • public String readLine() • returns null on EOF