如题啊,我准备将一个中文文件名转换成英文的,比如说“测试_001.java”,通过调用properties将“测试”改为“test”,但是改完后只能输出test,不能输出我想要的“test_001.java”,请问这个方法该怎么写啊,谢谢啊!!!

解决方案 »

  1.   

    首先检查页面中输出的内容是不是从对应的properties属性文件里读取出来的,
    再properties属性文件读取中文是要经过编码的,你是否经过编码或有相关的编码插件.
    认真检查一下...
      

  2.   

    通过调用properties将“测试”改为“test”???什么意思?
      

  3.   

    作为多国语言对应的话,key值应该设定正确。
    “测试”应该和“test”是同一个key值吧。
    ---纯属个人理解。
      

  4.   


    import java.util.ResourceBundle;public class Resource
    {
    public static void main(String[] args)
    {
    ResourceBundle rs = ResourceBundle.getBundle("msg");
    System.out.print(rs.getString("key"));
    }
    }msg_zh.properties:
    key=\u6d4b\u8bd5_001.java  (“测试”的ASCII字符)
    msg.properties
    key=test_001.java
      

  5.   

    编码上没什么问题,问题是在循环上,因为我是将要替换的先转换成字符串,然后每个字符和properties里面的Unicode码进行匹配,由于properties中无对应的Unicode码,因此输出的是为“null”的,所以显示的是空白的,
    public void readFile(String fileName) {
    String b="";
    exchanged = "";//在外部已定义
    String transefer ="";
    InputStream in = null;
    Properties pros = new Properties();
    try {  
    if (null != fileName) {
    in = Protest.class.getResourceAsStream(fileName);//得到当前类的路径,并把资源文件名作为输入流
    pros.load(in);
    char d[] = needExChange.getText().toCharArray();
    for(int i=0;i<d.length;i++){
    b = String.valueOf(d[i]);
    transefer = pros.getProperty(b);
    if(transefer==null)
    transefer = b;
    exchanged+=transefer;
    }
    }
    } catch (IOException e) {
    e.printStackTrace();
    } finally {
    try {
    if (null != in) {
    in.close();
    }
    } catch (IOException e) {
    e.printStackTrace();
    }
    }
    }后来将这些无匹配项的字符,保存起来,然后再输出,这样问题就解决了!