Powered by Ajaxy
Digg StumbleUpon LinkedIn YouTube Flickr Facebook Twitter RSS Reset

Java: Change the encoding of a file

Java: Change the encoding of a file
{filelink=12371}

import java.io.*;
import java.io.IOException;
public class File_Enc
oding
 {
private static void Encoding_de(String file_src,String file_dest, String ancien_enc, String new_enc) throws IOException
{
	   FileInputStream src =  new FileInputStream(file_src);
	   BufferedReader r =new BufferedReader(new InputStreamReader(src, ancien_enc));
	   FileOutputStream dest = new FileOutputStream(file_dest);
       Writer w = new BufferedWriter(new OutputStreamWriter(dest, new_enc));
       String donnee;
       while ( (donnee= r.readLine()) != null) {
          w.write(donnee);
          w.flush();
        }
        w.close();
        r.close();
        System.exit(0);
}
  public static void main(String args[]) throws Exception{
          Encoding_de("c:/test.txt","c:/testUTF.txt","CP850","UTF8");
  }
}

No comments yet.

Leave a Comment