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.newFactory();
    XMLStreamReader xsr = xif.createXMLStreamReader(new FileReader("data.xml"));
    xsr.nextTag(); // advance to Employees tag
    xsr.nextTag(); // advance to first Employer element
    Map<String, String> map = new HashMap<String, String>();
    while (xsr.getLocalName().equals("Employee")) {
        map.put(xsr.getAttributeValue("", "id"), xsr.getElementText());
        xsr.nextTag(); // advance to next Employer element
    }//from   w  ww . j  a  v a 2s  .  com
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    File archivo = new File("c:/Java_Dev/run.bat");
    FileReader fr = new FileReader(archivo);
    BufferedReader br = new BufferedReader(fr);

    Vector<String> lines = new Vector<String>();

    String line;/*ww w .  j  av  a2  s  .  c o m*/
    while ((line = br.readLine()) != null) {
        lines.add(line);
    }
    JOptionPane.showMessageDialog(null, new JScrollPane(new JList(lines)));
    fr.close();
}

From source file:Main.java

public static void main(String args[]) throws Exception {
    XMLInputFactory xmlif = XMLInputFactory.newInstance();
    XMLStreamReader xmlsr = xmlif.createXMLStreamReader(new FileReader("points.xml"));
    int eventType;
    while (xmlsr.hasNext()) {
        eventType = xmlsr.next();//w ww . j  av a2s . c  om
        switch (eventType) {
        case XMLEvent.START_ELEMENT:
            System.out.println(xmlsr.getName());
            break;
        case XMLEvent.CHARACTERS:
            System.out.println(xmlsr.getText());
            break;
        default:
            break;
        }
    }
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    XPath xPath = XPathFactory.newInstance().newXPath();

    FileReader reader = new FileReader("input.xml");
    InputSource xml = new InputSource(reader);
    NodeList titleNodes = (NodeList) xPath.evaluate("//item/title", xml, XPathConstants.NODESET);

    for (int x = 0; x < titleNodes.getLength(); x++) {
        System.out.println(titleNodes.item(x).getTextContent());
    }/* w  w  w  .  j  av  a2s. c o m*/
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    XMLInputFactory factory = XMLInputFactory.newInstance();

    Reader fileReader = new FileReader("source.xml");
    XMLStreamReader reader = factory.createXMLStreamReader(fileReader);

    while (reader.hasNext()) {
        process(reader);//w w  w.j  av  a 2 s .co m
        reader.next();
    }
}

From source file:Main.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  o m

    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);
}

From source file:GetName.java

public static void main(String[] args) throws Exception {
    XPathFactory factory = XPathFactory.newInstance();
    XPath xPath = factory.newXPath();

    String result = xPath.evaluate("/schedule/@name", new InputSource(new FileReader("tds.xml")));
    System.out.println(result);/*from   w ww.  j av  a  2 s. c o m*/
}

From source file:MainClass.java

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

    FileWriter fout = new FileWriter("test.txt");
    fout.write("2, 3.4,    5,6, 7.4, 9.1, 10.5, done");
    fout.close();//from  w  w w.  j a va 2 s .c  o m

    FileReader fin = new FileReader("Test.txt");
    Scanner src = new Scanner(fin);
    // Set delimiters to space and comma.
    // ", *" tells Scanner to match a comma and zero or more spaces as
    // delimiters.

    src.useDelimiter(", *");

    // Read and sum numbers.
    while (src.hasNext()) {
        if (src.hasNextDouble()) {
            System.out.println(src.nextDouble());
        } else {
            break;
        }
    }
    fin.close();
}

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("2 3.4 5 6 7.4 9.1 10.5 done");
    fout.close();//w w  w.  j a v a2  s  .co m

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

    Scanner src = new Scanner(fin);

    // Read and sum numbers.
    while (src.hasNext()) {
        if (src.hasNextDouble()) {
            System.out.println(src.nextDouble());
        } else {
            break;
        }
    }
    fin.close();
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    XPathFactory xpf = XPathFactory.newInstance();
    XPath xpath = xpf.newXPath();
    InputSource xml = new InputSource(new FileReader("input.xml"));
    Node result = (Node) xpath.evaluate("/tag1", xml, XPathConstants.NODE);
    System.out.println(result);//from www. j  a va  2 s  . c o  m
}