You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by Carfield Yim <ca...@carfield.com.hk> on 2003/01/31 19:04:44 UTC

Copy with filter have error on unicode

Hi, I try to write a simple ant task which act like a resource bundle on J2ME code, which using [copy] task to convert java file like this

        final Command cmSelect = new Command("@button.select@", Command.OK, 1);
to 
        final Command cmSelect = new Command("GO!", Command.OK, 1);

It work well in English, however, if I try to put some Chinese to replace the token, It change the text as something like

    [javac]         final Command cmSelect = new Command("?œç?å²?, Command.OK, 1);

Here is the code snap


    // The method executing the task
    public void execute() throws BuildException {
        copy.setEncoding("UTF-8");
        copy.setOverwrite(true);
        copy.setProject(this.getProject());
        FilterSet fs = copy.createFilterSet();
        for(int j=0; j<propKeys.size(); j++) {
            String key = (String)propKeys.get(j);
            fs.addFilter(key, property.getProperty(key));
        }
        replace(directory);
    }

    private void replace(File dir) {
        if(dir.listFiles() == null) return;
        File[] files = dir.listFiles();
        for(int i=0; i<files.length; i++) {
            File thisFile = files[i];
            if(thisFile.isDirectory()) {
                replace(thisFile);
            }
            else if (!thisFile.toString().endsWith("java")) {
                File toFile = new File(thisFile.getPath()+".java");
                copy.setFile(thisFile);
                copy.setTofile(toFile);
                copy.execute();
            }
        }
    }