Example usage for java.io FileWriter close

List of usage examples for java.io FileWriter close

Introduction

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

Prototype

public void close() throws IOException 

Source Link

Usage

From source file:Main.java

public static void main(String[] args) throws Exception {
    File file = new File("user.txt");

    FileWriter writer = new FileWriter(file, true);
    writer.write("username=java;password=secret" + System.getProperty("line.separator"));
    writer.flush();/* w w  w. ja  va2s  .co  m*/
    writer.close();
}

From source file:MainClass.java

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

    int i;/*  www  .jav  a  2 s. c o m*/
    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:MainClass.java

public static void main(String args[]) {

    try {//from   www. j  a v a 2s.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: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;// w  w  w  . j  a va  2 s .  c o  m
    while ((i = fr.read()) != -1) {
        fw.write(i);
    }
    fw.close();

    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;/*from  w w w  .ja va2 s  .c  o m*/

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

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

From source file:Main.java

public static void main(String[] argv) throws Exception {
    FileWriter fw = new FileWriter("file.dat");
    String strs[] = { "com", "exe", "doc" };

    for (int i = 0; i < strs.length; i++) {
        fw.write(strs[i] + "\n");
    }//  w  ww . j a va  2s  .  com
    fw.close();
}

From source file:de.mpg.escidoc.services.edoc.CreatePurgeScript2.java

/**
 * @param args/*from w  w w.  j a v a2  s.  com*/
 */
public static void main(String[] args) throws Exception {
    CORESERVICES_URL = PropertyReader.getProperty("escidoc.framework_access.framework.url");

    String userHandle = AdminHelper.loginUser(args[0], args[1]);

    logger.info("Querying core-services...");
    HttpClient httpClient = new HttpClient();
    String filter = "<param><filter name=\"http://escidoc.de/core/01/structural-relations/context\">"
            + IMPORT_CONTEXT
            + "</filter><filter name=\"/properties/public-status\">released</filter><order-by>http://escidoc.de/core/01/properties/creation-date</order-by><limit>0</limit></param>";

    PostMethod postMethod = new PostMethod(CORESERVICES_URL + "/ir/items/filter");
    postMethod.setRequestHeader("Cookie", "escidocCookie=" + userHandle);
    postMethod.setRequestBody(filter);

    ProxyHelper.executeMethod(httpClient, postMethod);
    String response = postMethod.getResponseBodyAsString();
    logger.info("...done!");

    FileWriter xmlData = new FileWriter("xmlData.xml");
    xmlData.write(response);
    xmlData.close();
    //System.out.println(response);

    logger.info("Transforming result...");
    XSLTTransform transform = new XSLTTransform();
    File stylesheet = new File("src/main/resources/itemlist2purgescript.xslt");
    FileOutputStream outputStream = new FileOutputStream("purge.sh");
    transform.transform(response, stylesheet, outputStream);
    logger.info("...done!");

    logger.info("Finished!");
}

From source file:FileWriterDemo.java

public static void main(String args[]) throws Exception {
    FileWriter fw = new FileWriter(args[0]);
    // Write strings to the file
    for (int i = 0; i < 12; i++) {
        fw.write("Line " + i + "\n");
    }/*from w ww . j  a v  a2 s . c  om*/

    // Close file writer
    fw.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);
    PreparedStatement stmt = conn.prepareStatement("SELECT name, description, data FROM documents ");
    ResultSet resultSet = stmt.executeQuery();
    while (resultSet.next()) {
        String name = resultSet.getString(1);
        String description = resultSet.getString(2);
        File data = new File("C:\\a.txt");
        Reader reader = resultSet.getCharacterStream(3);
        FileWriter writer = new FileWriter(data);
        char[] buffer = new char[1];
        while (reader.read(buffer) > 0) {
            writer.write(buffer);/*  www .  j a  v a  2s .  c o m*/
        }
        writer.close();
    }
    conn.close();
}

From source file:contractEditor.SPConfFileEditor.java

public static void main(String[] args) {

    JSONObject obj = new JSONObject();
    ArrayList fileList = new ArrayList();

    fileList.add("confSP" + File.separator + "HOST1.json");
    fileList.add("confSP" + File.separator + "HOST2.json");
    fileList.add("confSP" + File.separator + "HOST3.json");
    fileList.add("confSP" + File.separator + "HOST4.json");

    obj.put("contract_list_of_SP", fileList);

    try {//from   w  w  w . j  a  v a 2s .com

        FileWriter file = new FileWriter("confSP" + File.separator + "contractFileList.json");
        file.write(obj.toJSONString());
        file.flush();
        file.close();

    } catch (IOException e) {
        e.printStackTrace();
    }

    System.out.print(obj);

}