private static Locale defaultLocale = new Locale("zh", CN);
public static String getMessage(String msg,Object...objects) {
ResourceBundle resourceBundle = ResourceBundle.getBundle("MessageResource", defaultLocale);
MessageFormat messageFormat = new MessageFormat(resourceBundle.getString(msg));
String i18nMsg = messageFormat.format(objects);
return i18nMsg;
}
如何将国际化MessageResource_zh_CN.properties文件放到其它目录(不在项目目录),通过路径读取国际化文件?
或者有其它国际化的方法也可以。只要可以自定义国际化文件路径。
求解...
先谢了!!!
public static String getMessage(String msg,Object...objects) {
ResourceBundle resourceBundle = ResourceBundle.getBundle("MessageResource", defaultLocale);
MessageFormat messageFormat = new MessageFormat(resourceBundle.getString(msg));
String i18nMsg = messageFormat.format(objects);
return i18nMsg;
}
如何将国际化MessageResource_zh_CN.properties文件放到其它目录(不在项目目录),通过路径读取国际化文件?
或者有其它国际化的方法也可以。只要可以自定义国际化文件路径。
求解...
先谢了!!!
Properties prop = new Properties();
prop.load(new FileInputStream("xxxx.properties"));
Properties prop = new Properties();
prop.load(new FileInputStream("xxxx.properties"));
要用绝对路径了把,这样移植性不高哦,最好是放在src下,它也是源代码的一部分吗。
Properties prop = new Properties();
prop.load(new FileInputStream("xxxx.properties"));这个如果不在项目目录下,可以用ls这种方法:
测试了一下,可以用。properties文件在项目的根目录下。public class MyUserDetailService {
public static void main(String[] args){
InputStream in = MyUserDetailService.class.getClassLoader().getResourceAsStream("..\\db_config.properties");
Properties pro = new Properties();
try {
pro.load(in);
System.out.println(pro.getProperty("driver"));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
prop.load(new FileInputStream("xxxx.properties"));可能没法做到...
求解》。。
调用一下String.format就可以了