Írás szöveges fájlba – 4

package fajl_irasszovegesbe5;
import java.io.*;
public class Fajl_IrasSzovegesbe5 {
    public static void main(String[] args) {
       try{
          FileWriter fw = new FileWriter("szoveg.txt", true);
          //OutputStreamWriter osw;
          System.out.println(fw.getEncoding());
          String karKod = fw.getEncoding();
          //OutputStream is = null;
          OutputStream os = new FileOutputStream("szoveg.txt",true);
          OutputStreamWriter osw = new OutputStreamWriter(os,karKod);//Így nem jó!!!
          //Így a jó:
          //OutputStreamWriter osw = new OutputStreamWriter(os,"UTF-8");
          osw.write("Hajdunanas");
          //fw.write("Hajdúnánás");
          //fw.close();
          osw.close();
       }catch(IOException e){System.out.println(e);}
    }
}