// Collection of code snippets by Arne VajhÃ¸j 
// (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) 
import java.io.BufferedWriter;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.Writer;
import java.nio.channels.Channels;
import java.nio.charset.Charset;
import java.nio.charset.CharsetEncoder;
import java.nio.charset.CodingErrorAction;

public class CharsetProblems {
    public static void main(String[] args) throws IOException {
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream("C:\\io.txt"), "us-ascii"));
        bw.write("ÆØÅæøå");
        bw.close();
        CharsetEncoder cse = Charset.forName("us-ascii").newEncoder();
        cse.onUnmappableCharacter(CodingErrorAction.REPORT);
        //cse.onUnmappableCharacter(CodingErrorAction.REPLACE);
        //cse.replaceWith("#".getBytes());
        Writer w = Channels.newWriter(Channels.newChannel(new FileOutputStream("C:\\nio.txt")), cse, 512);
        w.write("ÆØÅæøå");
        w.close();
    }
}
