FileDocCategorySizeDatePackage
CharacterSetConverter.javaAPI DocExample1099Sun Mar 28 19:09:00 BST 1999None

CharacterSetConverter

public class CharacterSetConverter extends Object

Fields Summary
Constructors Summary
Methods Summary
public static voidmain(java.lang.String[] args)

      
    if (args.length < 2) {
      System.err.println(
       "Usage: java CharacterSetConverter infile_encoding outfile_encoding infile outfile");
      return;
    }
    
    try {
      
      File infile = new File(args[2]);
      File outfile = new File(args[3]);
      
      if (infile.getCanonicalPath().equals(outfile.getCanonicalPath())) {
        System.err.println("Can't convert file in place");
        return;
      }
    
      FileInputStream fin = new FileInputStream(infile);
      FileOutputStream fout = new FileOutputStream(outfile);
      InputStreamReader isr = new InputStreamReader(fin, args[0]);
      OutputStreamWriter osw = new OutputStreamWriter(fout, args[1]);
      
      while (true) {
        int c = isr.read();
        if (c == -1) break;  // end of stream
        osw.write(c);
      }
      
      osw.close();
      isr.close();
    }
    catch (IOException e) {
      System.err.println(e);
    }