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 IOException { // Write output to a file. FileWriter fout = new FileWriter("test.txt"); fout.write("int: 1 double 1.0 boolean true"); fout.close();/* w w w . ja v a 2s. c o m*/ FileReader fin = new FileReader("Test.txt"); Scanner src = new Scanner(fin); while (src.hasNext()) { if (src.hasNextInt()) { System.out.println("int: " + src.nextInt()); } else if (src.hasNextDouble()) { System.out.println("double: " + src.nextDouble()); } else if (src.hasNextBoolean()) { System.out.println("boolean: " + src.nextBoolean()); } else { System.out.println(src.next()); } } fin.close(); }
From source file:Main.java
public static void main(String[] args) { try {//from w w w. ja va2 s. c o m BufferedReader input = new BufferedReader(new FileReader(args[0])); ArrayList list = new ArrayList(); String line; while ((line = input.readLine()) != null) { list.add(line); } input.close(); Collections.reverse(list); PrintWriter output = new PrintWriter(new BufferedWriter(new FileWriter(args[1]))); for (Iterator i = list.iterator(); i.hasNext();) { output.println((String) i.next()); } output.close(); } catch (IOException e) { System.err.println(e); } }
From source file:Main.java
public static void main(String args[]) throws Exception { File file = new File("."); if (file.isDirectory()) { String[] files = file.list(); for (int i = 0; i < files.length; i++) System.out.println(files[i]); } else {/*from w w w . j a v a2s. c o m*/ FileReader fr = new FileReader(file); BufferedReader in = new BufferedReader(fr); String line; while ((line = in.readLine()) != null) System.out.println(line); } }
From source file:Main.java
public static void main(String[] args) throws Exception { Socket sock = new Socket(args[0], Integer.parseInt(args[1])); GZIPOutputStream zip = new GZIPOutputStream(sock.getOutputStream()); String line;//from w w w . j a va 2 s . com BufferedReader bis = new BufferedReader(new FileReader(args[2])); while (true) { line = bis.readLine(); if (line == null) break; line = line + "\n"; zip.write(line.getBytes(), 0, line.length()); } zip.finish(); zip.close(); sock.close(); }
From source file:MainClass.java
public static void main(String args[]) throws IOException { Hashtable map = new Hashtable(); FileReader fr = new FileReader(args[0]); BufferedReader br = new BufferedReader(fr); String line;/*w w w.ja va 2 s . com*/ while ((line = br.readLine()) != null) { processLine(line, map); } Enumeration e = map.keys(); while (e.hasMoreElements()) { String key = (String) e.nextElement(); System.out.println(key + " : " + map.get(key)); } }
From source file:WordCount.java
public static void main(String args[]) throws IOException { Hashtable map = new Hashtable(); FileReader fr = new FileReader(args[0]); BufferedReader br = new BufferedReader(fr); String line;/* w ww . j av a2 s . c om*/ while ((line = br.readLine()) != null) { processLine(line, map); } Enumeration e = map.keys(); while (e.hasMoreElements()) { String key = (String) e.nextElement(); System.out.println(key + " : " + map.get(key)); } }
From source file:GetSeriesId.java
public static void main(String[] args) throws Exception { XPathFactory factory = XPathFactory.newInstance(); XPath xPath = factory.newXPath(); Double result = (Double) xPath.evaluate("/schedule/@seriesId", new InputSource(new FileReader("tds.xml")), XPathConstants.NUMBER); System.out.println(result.intValue()); }
From source file:AllCapsDemo.java
License:asdf
public static void main(String[] arguments) { String sourceName = "asdf"; try {//from ww w . jav a 2s . co m File source = new File(sourceName); File temp = new File("cap" + sourceName + ".tmp"); FileReader fr = new FileReader(source); BufferedReader in = new BufferedReader(fr); FileWriter fw = new FileWriter(temp); BufferedWriter out = new BufferedWriter(fw); boolean eof = false; int inChar = 0; do { inChar = in.read(); if (inChar != -1) { char outChar = Character.toUpperCase((char) inChar); out.write(outChar); } else eof = true; } while (!eof); in.close(); out.close(); boolean deleted = source.delete(); if (deleted) temp.renameTo(source); } catch (Exception se) { System.out.println("Error - " + se.toString()); } }
From source file:GuestListCounter.java
public static void main(String[] args) throws Exception { XPathFactory factory = XPathFactory.newInstance(); XPath xPath = factory.newXPath(); Number shows = (Number) xPath.evaluate("count(/schedule/show)", new InputSource(new FileReader("tds.xml")), XPathConstants.NUMBER); System.out.println("Document has " + shows.intValue() + " shows."); }
From source file:MainClass.java
public static void main(String args[]) throws IOException { int count = 0; double sum = 0.0; FileWriter fout = new FileWriter("test.txt"); fout.write("2, 3.4, 5,6, 7.4, 9.1, 10.5, done"); fout.close();/*from w ww. j a v a 2 s . c om*/ FileReader fin = new FileReader("Test.txt"); Scanner src = new Scanner(fin); src.useDelimiter(", *"); while (src.hasNext()) { if (src.hasNextDouble()) { sum += src.nextDouble(); count++; } else { String str = src.next(); if (str.equals("done")) break; else { System.out.println("File format error."); return; } } } fin.close(); System.out.println("Average is " + sum / count); }