//这是我的想法.希望对你有用.别忘了给我分呀.
import java.util.*;
import java.io.*;
import java.lang.*;class GetChar{
 Properties props;
 StringBuffer buffer1,buffer2; public GetChar(){
  props = new Properties();
  loadProperties();
 }
 
 public void loadProperties(){
  try{FileInputStream in = new FileInputStream("value.txt");
      props.load(in); 
   }
  catch(Exception e){}
 }
 
 public String find(String s){
  String chinesevalue = props.getProperty(s);
  try{
   byte temp[]=chinesevalue.getBytes("ISO8859_1");
   chinesevalue= new String(temp,"GB2312");
  }
  catch(Exception e){}
  return chinesevalue;
} public void getChar(String s){
    buffer1 = new StringBuffer();
    buffer2 = new StringBuffer();    try{ 
      ByteArrayInputStream bufferline = new ByteArrayInputStream(s.getBytes());
   for(int i = bufferline.read();i!=-1;i = bufferline.read()){
         char ch=(char)i;
         Character character = new Character(ch);
         if(character.isDigit(ch)) {
            String ss = character.toString();
            buffer1.append(ss);
         }
   }
  
  String temp = buffer1.toString();    
  int len = temp.length();
  for(int i = 0,j=len-1;i<=len-1;i++,j--){
        buffer2.append(temp.charAt(i));
        buffer2.append(find(Integer.toString(j)));
  }
   }   
   catch(Exception e){}
   System.out.println(buffer2);
 }}public class Change {
 static GetChar getchar = new GetChar();
 public Change(){
 }
 public static void main(String args[]){
   try{ 
FileInputStream fis = new FileInputStream("test.txt");   
      BufferedReader dis = new BufferedReader(new InputStreamReader(fis));
      for(String s = dis.readLine(); s != null; s = dis.readLine()){
       getchar.getChar(s);
       System.out.println("**********");

      fis.close();
      dis.close();
   }
  catch(Exception e){}
 }
}//test.txt
a:1
b:16
c:20
d:300
e:4222//value.txt
0=个
1=十
2=百
3=千

解决方案 »

  1.   

    //改进
    import java.util.*;
    import java.io.*;
    import java.lang.*;class GetChar{
     Properties props1,props2;
     StringBuffer buffer1,buffer2; public GetChar(){
      props1 = new Properties();
      props2 = new Properties();
      loadProperties();
      
     }
     
     public void loadProperties(){
      try{FileInputStream in = new FileInputStream("value.txt");
          props1.load(in); 
          FileInputStream in2 = new FileInputStream("chinese.txt");
          props2.load(in2);
       }
      catch(Exception e){}
     }
     
     public String find(String s){
      String chinesevalue = props1.getProperty(s);
      try{
       byte temp[]=chinesevalue.getBytes("ISO8859_1");
       chinesevalue= new String(temp,"GB2312");
      }
      catch(Exception e){}
      return chinesevalue;
    }public String findchinese(String s){
      String chinesevalue = props2.getProperty(s);
      try{
       byte temp[]=chinesevalue.getBytes("ISO8859_1");
       chinesevalue= new String(temp,"GB2312");
      }
      catch(Exception e){}
      return chinesevalue;
    } public void getChar(String s){
        buffer1 = new StringBuffer();
        buffer2 = new StringBuffer();    try{ 
          ByteArrayInputStream bufferline = new ByteArrayInputStream(s.getBytes());
       for(int i = bufferline.read();i!=-1;i = bufferline.read()){
             char ch=(char)i;
             Character character = new Character(ch);
             if(character.isDigit(ch)) {
                buffer1.append(findchinese(character.toString()));
             }
       }
      
      String temp = buffer1.toString();    
      int len = temp.length();
      for(int i = 0,j=len-1;i<=len-1;i++,j--){
            buffer2.append(temp.charAt(i));
            buffer2.append(find(Integer.toString(j)));
      }
       }   
       catch(Exception e){}
       System.out.println(buffer2);
     }}public class Change {
     static GetChar getchar = new GetChar();
     public Change(){
     }
     public static void main(String args[]){
       try{ 
    FileInputStream fis = new FileInputStream("test.txt");   
          BufferedReader dis = new BufferedReader(new InputStreamReader(fis));
          for(String s = dis.readLine(); s != null; s = dis.readLine()){
           getchar.getChar(s);
           System.out.println("**********");

          fis.close();
          dis.close();
       }
      catch(Exception e){}
     }
    }//test.txt
    a:1
    b:16
    c:20
    d:300
    e:4222//value.txt
    0=个
    1=十
    2=百
    3=千 //chinese.txt
    0=零
    1=一
    2=二
    3=三
    4=四
    5=五
    6=六
    7=七
    8=八
    9=九
      

  2.   

    @o@ ... 越编越糊涂 ... 帮忙看看是不是还有问题吧 ...
    --
    public class converter {    private String[] _cnum   = {"零", "壹", "贰", "叁", "肆", "伍", "陆", "戚", "捌", "玖"};
        private String[] _levl   = {"", "拾", "佰", "仟", "萬", "拾", "佰", "仟"};
        private String[] _unit   = {"元", "点"};
        private String[] _spec   = {"分", "角"};    private boolean _no_unit = false;    public void setMode(boolean no_unit) {
            _no_unit = no_unit;
        }    public String convert(float f) throws Exception {
            StringBuffer tmp_str = new StringBuffer("1");
            for (int i=0; i<_levl.length; i++) {
                tmp_str.append("0");
            }
            float fmax = Float.parseFloat(tmp_str.toString());
            if (f >= fmax)
                throw new Exception("Sorry, ["+f+"] should less than ["+fmax+"]");
            return convert(Float.toString(f));
        }    public String convert(int i) throws Exception {
            StringBuffer tmp_str = new StringBuffer("1");
            for (int j=0; j<_levl.length; j++) {
                tmp_str.append("0");
            }
            int imax = Integer.parseInt(tmp_str.toString());
            if (i >= imax)
                throw new Exception("Sorry, ["+i+"] should less than ["+imax+"]");
            return convert(Integer.toString(i));
        }    public String convert(String str) throws Exception {
            if ((str == null) || (str.trim().equals(""))) {
                return _cnum[0];
            }        String ret_str = "";        int len = str.length();
            int idx = -1;
            if ((idx = str.indexOf('.')) < 0) {
                idx = len;
            }
            --idx;        ret_str += conv(str, idx, -1, _levl, false);        if (!_no_unit)
                ret_str += _unit[0];
            else
                ret_str += _unit[1];        if (len > idx+1) {
                int critical = idx + 1 + _spec.length;
                if (critical >= len)
                    critical = len -1;
                ret_str += _levl[0] + conv(str, critical, idx+1, _spec, true);
            }        return ret_str;
        }    private String conv(String str, int start, int end, String[] strs, boolean c) throws Exception {
            int    n = 0;
            if (c) {
                n = strs.length - start + end;
                n = (n<0)?0:n;
            }
            System.out.println(n);
            boolean hasZero = false;
            String ret_str = "";        for (int i=start; i>end; i--) {
                String tmp_str = str.substring(i, i+1);            if (tmp_str != null) {
                    if (tmp_str.equals("0")) {
                        if (!hasZero) {
                            if (n > 0) {
                                ret_str = _cnum[Integer.parseInt(tmp_str)] + ret_str;
                            }
                            hasZero = true;
                        } else if (_no_unit) {
                            ret_str = _cnum[Integer.parseInt(tmp_str)] + ret_str;
                        }
                    } else {
                        hasZero = false;
                        ret_str = _cnum[Integer.parseInt(tmp_str)] + ((_no_unit)?"":strs[n]) + ret_str;
                    }
                } else {
                    ret_str = "error!";
                    break;
                }
                n++;
            }        return ret_str;
        }    public converter() {
        }
        public static void main(String[] args) {
            converter converter1 = new converter();
            float f = 34.9f;        try {
                System.out.println("* [" + f + "] => [" + converter1.convert(f) + "]");
                converter1.setMode(true);
                System.out.println("* [" + f + "] => [" + converter1.convert(f) + "]");
            }
            catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
    --希望大家不吝赐教, 谢谢!