Example usage for java.io FileReader close

List of usage examples for java.io FileReader close

Introduction

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

Prototype

public void close() throws IOException 

Source Link

Usage

From source file:Main.java

public static void main(String[] args) {
    ScriptEngineManager manager = new ScriptEngineManager();
    ScriptEngine engine = manager.getEngineByName("js");
    try {//  w ww .  ja v a2 s .  c  o m
        FileReader reader = new FileReader("yourFile.js");
        engine.eval(reader);
        reader.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

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

}

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 source file:Main.java

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

    Class.forName("oracle.jdbc.driver.OracleDriver");
    Connection conn = DriverManager.getConnection(url, username, password);
    conn.setAutoCommit(false);//from ww  w  .j a va2  s  .  com

    String sql = "INSERT INTO documents (name, description, data) VALUES (?, ?, ?)";
    PreparedStatement stmt = conn.prepareStatement(sql);
    stmt.setString(1, "a.txt");
    stmt.setString(2, "b");

    File data = new File("C:\\a.txt");
    FileReader reader = new FileReader(data);
    stmt.setCharacterStream(3, reader, (int) data.length());
    stmt.execute();

    conn.commit();
    reader.close();
    conn.close();

}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    FileReader fr = new FileReader("text.txt");

    int ch;/*from   w  w w. ja  va2 s . c om*/
    do {
        ch = fr.read();
        if (ch != -1)
            System.out.println((char) ch);
    } while (ch != -1);
    fr.close();
}

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 w w  w .  j av a 2  s.  c o  m*/
    while ((i = fr.read()) != -1) {
        System.out.println((char) i);

    }

    // Close file reader
    fr.close();
}

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  ww .jav a2 s .  c om*/

    while ((c = in.read()) != -1)
        out.write(c);

    in.close();
    out.close();
}

From source file:FileReaderDemo.java

public static void main(String args[]) throws IOException {
    FileReader fr = new FileReader("FileReaderDemo.java");
    BufferedReader br = new BufferedReader(fr);
    String s;/*from www.j a  v  a 2  s. c o  m*/

    while ((s = br.readLine()) != null) {
        System.out.println(s);
    }

    fr.close();
}

From source file:Test.java

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

    final URL test = Test.class.getResource("/");
    System.out.println(test);/*  www .j  av  a2s . c  om*/

    final URL url = Test.class.getResource("/resources/test.txt");
    System.out.println(url);

    if (url == null) {
        System.out.println("URL is null");
    } else {
        final File file = new File(url.toURI());
        final FileReader reader = new FileReader(file);
        final char[] buff = new char[20];
        final int l = reader.read(buff);
        System.out.println(new String(buff, 0, l));
        reader.close();
    }

}