Example usage for java.io FileReader FileReader

List of usage examples for java.io FileReader FileReader

Introduction

In this page you can find the example usage for java.io FileReader FileReader.

Prototype

public FileReader(FileDescriptor fd) 

Source Link

Document

Creates a new FileReader , given the FileDescriptor to read, using the platform's java.nio.charset.Charset#defaultCharset() default charset .

Usage

From source file:Main.java

public static void main(String[] args) throws Exception {
    XMLInputFactory xif = XMLInputFactory.newInstance();
    XMLStreamReader xsr = xif.createXMLStreamReader(new FileReader("input.xml"));
    xsr.nextTag(); // Advance to statements element

    while (xsr.nextTag() == XMLStreamConstants.START_ELEMENT) {
        TransformerFactory tf = TransformerFactory.newInstance();
        Transformer t = tf.newTransformer();
        File file = new File("out" + xsr.getAttributeValue(null, "account") + ".xml");
        t.transform(new StAXSource(xsr), new StreamResult(file));
    }//from  w  ww.j  a v  a 2 s.  c o m
}

From source file:MainClass.java

public static void main(String args[]) throws IOException {
    int i;/*w ww  .ja va2 s.c o m*/
    double d;
    boolean b;
    String str;

    FileWriter fout = new FileWriter("test.txt");
    fout.write("string true false 1 2 3 4.12");
    fout.close();

    FileReader fin = new FileReader("Test.txt");

    Scanner src = new Scanner(fin);

    while (src.hasNext()) {
        if (src.hasNextInt()) {
            i = src.nextInt();
            System.out.println("int: " + i);
        } else if (src.hasNextDouble()) {
            d = src.nextDouble();
            System.out.println("double: " + d);
        } else if (src.hasNextBoolean()) {
            b = src.nextBoolean();
            System.out.println("boolean: " + b);
        } else {
            str = src.next();
            System.out.println("String: " + str);
        }
    }

    fin.close();
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    XMLInputFactory xif = XMLInputFactory.newInstance();
    XMLStreamReader xsr = xif.createXMLStreamReader(new FileReader("input.xml"));
    xsr.nextTag(); // Advance to statements element

    TransformerFactory tf = TransformerFactory.newInstance();
    Transformer t = tf.newTransformer();
    while (xsr.nextTag() == XMLStreamConstants.START_ELEMENT) {
        DOMResult result = new DOMResult();
        t.transform(new StAXSource(xsr), result);
        Node domNode = result.getNode();
    }/*  w  w  w .  jav  a  2 s .  c  o m*/
}

From source file:Vis.java

public static void main(String[] av) {
    Vis v = new Vis();
    if (av.length == 0)
        v.process(new BufferedReader(new InputStreamReader(System.in)));
    else/*  w w  w .  j a  v  a 2 s  . c  om*/
        for (int i = 0; i < av.length; i++)
            try {
                v.process(new BufferedReader(new FileReader(av[i])));
            } catch (FileNotFoundException e) {
                System.err.println(e);
            }
}

From source file:LoadingHTMLDocuments.java

public static void main(String args[]) throws Exception {
    JFrame frame = new JFrame("Tab Attributes");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JEditorPane editorPane = new JEditorPane();
    editorPane.setEditorKit(new HTMLEditorKit());

    String filename = "yourFile.htm";

    FileReader reader = new FileReader(filename);
    editorPane.read(reader, filename);/*  www .j a  v a2 s. c om*/

    JScrollPane scrollPane = new JScrollPane(editorPane);
    frame.add(scrollPane, BorderLayout.CENTER);

    frame.setSize(300, 150);
    frame.setVisible(true);
}

From source file:FuncEvaluator.java

  public static void main(String[] args) {
  if (args.length != 2) {
    System.err/*  www. j  a  v a 2  s  . c o m*/
        .println("usage: java FuncEvaluator scriptfile " + "script-exp");
    return;
  }

  ScriptEngineManager manager = new ScriptEngineManager();
  ScriptEngine engine = manager.getEngineByName("rhino");

  try {
    System.out.println(engine.eval(new FileReader(args[0])));
    System.out.println(engine.eval(args[1]));
  } catch (ScriptException se) {
    System.err.println(se.getMessage());
  } catch (IOException ioe) {
    System.err.println(ioe.getMessage());
  }
}

From source file:MainClass.java

public static void main(String args[]) throws IOException {

    int i;//from   ww  w  .j a v  a 2  s .  c om
    double d;
    boolean b;
    String str;

    FileWriter fout = new FileWriter("test.txt");
    fout.write("Testing Scanner 10 12.2 one true two false");
    fout.close();

    FileReader fin = new FileReader("Test.txt");

    Scanner src = new Scanner(fin);

    while (src.hasNext()) {
        if (src.hasNextInt()) {
            i = src.nextInt();
            System.out.println("int: " + i);
        } else if (src.hasNextDouble()) {
            d = src.nextDouble();
            System.out.println("double: " + d);
        } else if (src.hasNextBoolean()) {
            b = src.nextBoolean();
            System.out.println("boolean: " + b);
        } else {
            str = src.next();
            System.out.println("String: " + str);
        }
    }

    fin.close();
}

From source file:GrepReader.java

public static void main(String args[]) {
    try {/*from ww w.  j  ava2  s  .com*/
        GrepReader in = new GrepReader(new FileReader("GrepReader.java"), "GrepReader");
        String line;
        while ((line = in.readLine()) != null)
            System.out.println(line);
        in.close();
    } catch (Exception e) {
        System.err.println(e);
    }
}

From source file:XMLEventReaderDemo.java

public static void main(String[] args) throws Exception {
    XMLInputFactory factory = XMLInputFactory.newInstance();
    Reader fileReader = new FileReader("Source.xml");
    XMLEventReader reader = factory.createXMLEventReader(fileReader);

    while (reader.hasNext()) {
        XMLEvent event = reader.nextEvent();
        if (event.isStartElement()) {
            StartElement element = (StartElement) event;
            System.out.println("Start Element: " + element.getName());

            Iterator iterator = element.getAttributes();
            while (iterator.hasNext()) {
                Attribute attribute = (Attribute) iterator.next();
                QName name = attribute.getName();
                String value = attribute.getValue();
                System.out.println("Attribute name/value: " + name + "/" + value);
            }//w  w w  .  j  a  va  2 s .  com
        }
        if (event.isEndElement()) {
            EndElement element = (EndElement) event;
            System.out.println("End element:" + element.getName());
        }
        if (event.isCharacters()) {
            Characters characters = (Characters) event;
            System.out.println("Text: " + characters.getData());
        }
    }
}

From source file:Print.java

public static void main(String[] args) throws Exception {
    Hashtable env = new Hashtable();
    env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.fscontext.RefFSContextFactory");

    env.put(Context.PROVIDER_URL, "file:/tmp/marketing");

    Context initCtx = new InitialContext(env);
    File f = (File) initCtx.lookup("reports/report1.txt");
    if (f != null) {
        BufferedReader br = new BufferedReader(new FileReader(f));
        String l = null;//from w w  w  .  ja v a 2 s.  co m
        while ((l = br.readLine()) != null)
            System.out.println(l);
    }

}