Skip to main content
Fixed indentation and reworded the top text to be more clear.
Source Link

Here's a little program example program to create/overwrite or overwrite a file,. It's the LONGlong version, to get to understand so it can be understood more easily what's going on and where it is all going.

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.Writer;

public class writer {
    public void writing() {
        try {
            //What everWhatever the file path is.
            File statText = new File("E:/Java/Reference/bin/images/statsTest.txt");
            FileOutputStream is = new FileOutputStream(statText);
            OutputStreamWriter osw = new OutputStreamWriter(is);    
            Writer w = new BufferedWriter(osw);
            w.write("POTATO!!!");
            w.close();
        } catch (IOException e) {
            System.err.println("Problem writing to the file statsTest.txt");
        }
    }
    
    public static void main(String[]args) {
        writer write = new writer();
        write.writing();
    }
}

Here's a little program example to create/overwrite a file, the LONG version, to get to understand more easily what's going on and where it is all going.

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.Writer;

public class writer {
public void writing() {
    try {
//What ever the file path is.
        File statText = new File("E:/Java/Reference/bin/images/statsTest.txt");
        FileOutputStream is = new FileOutputStream(statText);
        OutputStreamWriter osw = new OutputStreamWriter(is);    
        Writer w = new BufferedWriter(osw);
        w.write("POTATO!!!");
        w.close();
    } catch (IOException e) {
        System.err.println("Problem writing to the file statsTest.txt");
    }
}

public static void main(String[]args) {
    writer write = new writer();
    write.writing();
}
}

Here's a little example program to create or overwrite a file. It's the long version so it can be understood more easily.

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.Writer;

public class writer {
    public void writing() {
        try {
            //Whatever the file path is.
            File statText = new File("E:/Java/Reference/bin/images/statsTest.txt");
            FileOutputStream is = new FileOutputStream(statText);
            OutputStreamWriter osw = new OutputStreamWriter(is);    
            Writer w = new BufferedWriter(osw);
            w.write("POTATO!!!");
            w.close();
        } catch (IOException e) {
            System.err.println("Problem writing to the file statsTest.txt");
        }
    }
    
    public static void main(String[]args) {
        writer write = new writer();
        write.writing();
    }
}

Here's a little program example to create/overwrite a file, the LONG version, to get to understand more easily what's going on and where it is all going.

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.Writer;

public class writer {
public void writing() {
    try {
//What ever the file path is.
        File statText = new File("E:/Java/Reference/bin/images/statsTest.txt");
        FileOutputStream is = new FileOutputStream(statText);
        OutputStreamWriter osw = new OutputStreamWriter(is);    
        Writer w = new BufferedWriter(osw);
        w.write("PATATE"POTATO!!!");
        w.close();
    } catch (IOException e) {
        System.err.println("Problème"Problem d'écriturewriting duto fichierthe file statsTest.txt");
    }
}

public static void main(String[]args) {
    writer write = new writer();
    write.writing();
}
}

Here's a little program example to create/overwrite a file, the LONG version, to get to understand more easily what's going on and where it is all going.

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.Writer;

public class writer {
public void writing() {
    try {
//What ever the file path is.
        File statText = new File("E:/Java/Reference/bin/images/statsTest.txt");
        FileOutputStream is = new FileOutputStream(statText);
        OutputStreamWriter osw = new OutputStreamWriter(is);    
        Writer w = new BufferedWriter(osw);
        w.write("PATATE!!!");
        w.close();
    } catch (IOException e) {
        System.err.println("Problème d'écriture du fichier statsTest.txt");
    }
}

public static void main(String[]args) {
    writer write = new writer();
    write.writing();
}
}

Here's a little program example to create/overwrite a file, the LONG version, to get to understand more easily what's going on and where it is all going.

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.Writer;

public class writer {
public void writing() {
    try {
//What ever the file path is.
        File statText = new File("E:/Java/Reference/bin/images/statsTest.txt");
        FileOutputStream is = new FileOutputStream(statText);
        OutputStreamWriter osw = new OutputStreamWriter(is);    
        Writer w = new BufferedWriter(osw);
        w.write("POTATO!!!");
        w.close();
    } catch (IOException e) {
        System.err.println("Problem writing to the file statsTest.txt");
    }
}

public static void main(String[]args) {
    writer write = new writer();
    write.writing();
}
}
Source Link
Draeven
  • 479
  • 4
  • 5

Here's a little program example to create/overwrite a file, the LONG version, to get to understand more easily what's going on and where it is all going.

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.Writer;

public class writer {
public void writing() {
    try {
//What ever the file path is.
        File statText = new File("E:/Java/Reference/bin/images/statsTest.txt");
        FileOutputStream is = new FileOutputStream(statText);
        OutputStreamWriter osw = new OutputStreamWriter(is);    
        Writer w = new BufferedWriter(osw);
        w.write("PATATE!!!");
        w.close();
    } catch (IOException e) {
        System.err.println("Problème d'écriture du fichier statsTest.txt");
    }
}

public static void main(String[]args) {
    writer write = new writer();
    write.writing();
}
}