List of usage examples for java.io FileReader read
public int read() throws IOException
From source file:Main.java
public static void main(String[] args) throws Exception { FileReader fileReader = new FileReader("c:/abc.txt"); System.out.println(fileReader.read()); fileReader.close();//from w w w . j a va 2s . c om }
From source file:Main.java
public static void main(String[] args) throws Exception { FileReader fileReader = new FileReader(new File("c:/abc.txt")); System.out.println(fileReader.read()); fileReader.close();//w ww . j av a 2 s . co m }
From source file:Main.java
public static void main(String[] argv) throws Exception { FileReader fr = new FileReader("text.txt"); int ch;/*from www . j a v a 2s. com*/ do { ch = fr.read(); if (ch != -1) System.out.println((char) ch); } while (ch != -1); fr.close(); }
From source file:Main.java
public static void main(String[] args) throws Exception { FileReader fileReader = new FileReader(new FileOutputStream("c:/abc.txt").getFD()); System.out.println(fileReader.read()); fileReader.close();/*from w w w. j a v a 2 s.c om*/ }
From source file:DigitCounter.java
public static void main(String args[]) throws Exception { // Create a file reader FileReader fr = new FileReader(args[0]); // Read characters int i;/*from ww w. j ava2s. c o m*/ while ((i = fr.read()) != -1) { System.out.println((char) i); } // Close file reader fr.close(); }
From source file:MainClass.java
public static void main(String args[]) { try {// w ww. j a v a 2 s .c o m int counts[] = new int[10]; FileReader fr = new FileReader(args[0]); int i; while ((i = fr.read()) != -1) { char c = (char) i; int k = c - '0'; if (k >= 0 && k < 10) ++counts[k]; } // Display digit counts for (int j = 0; j < 10; j++) { char c = (char) ('0' + j); System.out.print(c + "="); System.out.print(counts[j] + "; "); } fr.close(); } catch (Exception e) { System.out.println("Exception: " + e); } }
From source file:MainClass.java
public static void main(String args[]) { try {/*from w w w . ja v a 2 s .com*/ FileReader fr = new FileReader(args[0]); FileWriter fw = new FileWriter(args[1]); int i; while ((i = fr.read()) != -1) { fw.write(i); } fw.close(); fr.close(); } catch (Exception e) { System.out.println("Exception: " + e); } }
From source file:Copy.java
public static void main(String[] args) throws IOException { File inputFile = new File("farrago.txt"); File outputFile = new File("outagain.txt"); FileReader in = new FileReader(inputFile); FileWriter out = new FileWriter(outputFile); int c;/*w w w. java 2 s . com*/ while ((c = in.read()) != -1) out.write(c); in.close(); out.close(); }
From source file:WordCount.java
public static void main(String args[]) throws Exception { int words = 0; int lines = 0; int chars = 0; FileReader fr = new FileReader("yourFile.txt"); int c = 0;//from w w w .j a v a 2 s.c o m boolean lastWhite = true; String whiteSpace = " \t\n\r"; while ((c = fr.read()) != -1) { chars++; if (c == '\n') { lines++; } int index = whiteSpace.indexOf(c); if (index == -1) { if (lastWhite == true) { ++words; } lastWhite = false; } else { lastWhite = true; } } if (chars != 0) { ++lines; } }
From source file:FileCopy.java
public static void main(String args[]) throws Exception { FileReader fr = new FileReader(args[0]); // Create a file writer FileWriter fw = new FileWriter(args[1]); // Read and copy characters int i;/*from ww w. j ava 2 s . c om*/ while ((i = fr.read()) != -1) { fw.write(i); } fw.close(); fr.close(); }