Example usage for java.io FileWriter FileWriter

List of usage examples for java.io FileWriter FileWriter

Introduction

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

Prototype

public FileWriter(FileDescriptor fd) 

Source Link

Document

Constructs a FileWriter given a file descriptor, using the platform's java.nio.charset.Charset#defaultCharset() default charset .

Usage

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");
    }//  ww w.  j  a va  2 s . com
    fw.close();
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    FileWriter fileWriter = new FileWriter("c:/abc.txt");
    fileWriter.append("java2s.com");
    fileWriter.close();/*from w  w w  .java  2s.c  o  m*/

}

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  w w.j a  va 2  s.  c o  m*/

    // Close file writer
    fw.close();
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    FileWriter fileWriter = new FileWriter(new File("c:/abc.txt"));
    fileWriter.append("java2s.com");
    fileWriter.close();//from  w  ww . ja va 2s  .  com

}

From source file:Main.java

public static void main(String[] args) throws Exception {
    FileWriter fileWriter = new FileWriter(new FileOutputStream("c:/abc.txt").getFD());
    fileWriter.append("java2s.com");
    fileWriter.close();//from   www. ja v a2  s.c o  m

}

From source file:BufferedWriterDemo.java

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

    FileWriter fw = new FileWriter(args[0]);

    BufferedWriter bw = new BufferedWriter(fw);

    // Write strings to the file
    for (int i = 0; i < 12; i++) {
        bw.write("Line " + i + "\n");
    }/*  w w w .  ja v  a  2s .c  o m*/

    // Close buffered writer
    bw.close();
}

From source file:MainClass.java

public static void main(String[] a) {
    FileWriter writer;// w ww  . ja  v a  2  s  .c  om
    try {
        writer = new FileWriter("myFile.txt");
        char c = 'A';
        writer.write(c);
        writer.close();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    FileWriter file = new FileWriter("a.html");
    BufferedWriter buffer = new BufferedWriter(file);
    PrintWriter out = new PrintWriter(buffer);
    out.println("<html>\n\t<body>");
    out.println("\t</body>\n</html>");
    out.close();/*from  w  w  w  .ja  v a  2  s  .  co m*/
    buffer.close();
    file.close();
}

From source file:Main.java

public static void main(String[] args) {
    try {//from w  w  w .  j a  va  2 s  .  c  o  m
        PrintWriter pw = new PrintWriter(new FileWriter("c:/text.txt"));

        // append chars
        pw.append('H');
        pw.append('e');
        pw.append('l');
        pw.append('l');
        pw.append('o');

        // flush the writer
        pw.flush();
        pw.close();
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}

From source file:Main.java

public static void main(String[] args) {
    try {//  www.  ja v a 2  s  . c  o m
        PrintWriter pw = new PrintWriter(new FileWriter("c:/text.txt"), true);

        // append chars
        pw.append('H');
        pw.append('e');
        pw.append('l');
        pw.append('l');
        pw.append('o');

        // flush the writer
        pw.flush();
        pw.close();
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}