Collate File : RuleBasedCollator « I18N « Java






Collate File

 

import java.io.BufferedReader;
import java.io.FileReader;
import java.text.CollationKey;
import java.text.Collator;
import java.text.RuleBasedCollator;
import java.util.Locale;
import java.util.Vector;

class CollateApp {
  public static void main(String args[]) {
    if (args.length != 1) {
      System.out.println("Usage: java CollateApp file");
      System.exit(0);
    }
    Locale defaultLocale = Locale.getDefault();
    RuleBasedCollator collator = (RuleBasedCollator) Collator.getInstance(defaultLocale);
    Vector keyVector = new Vector();
    try {
      BufferedReader in = new BufferedReader(new FileReader(args[0]));
      String line;
      while ((line = in.readLine()) != null)
        keyVector.addElement(collator.getCollationKey(line));
      in.close();
    } catch (Exception ex) {
      System.out.println(ex);
      System.exit(0);
    }
    CollationKey keys[] = new CollationKey[keyVector.size()];
    for (int i = 0; i < keys.length; ++i)
      keys[i] = (CollationKey) keyVector.elementAt(i);
  }
}

 








Related examples in the same category

1.Sort Spanish with RuleBasedCollatorSort Spanish with RuleBasedCollator