public
class
MyMessages
extends
NLS{
private static final StringBUNDLE_NAME = "com.hedalixin " ; // $NON-NLS-1$
public static StringHELLO_WORLD;
public static StringHELLO_SOMETHING;
static {
// initializeresourcebundles
NLS.initializeMessages(BUNDLE_NAME,MyMessages. class );
}
}
private static final StringBUNDLE_NAME = "com.hedalixin " ; // $NON-NLS-1$
public static StringHELLO_WORLD;
public static StringHELLO_SOMETHING;
static {
// initializeresourcebundles
NLS.initializeMessages(BUNDLE_NAME,MyMessages. class );
}
}
资源文件MyMessages.property(上边的类名)的内容还是和以前一样:
HELLO_WORLD
=
Helloworld
!
HELLO_SOMETHING = Hello{ 0 } !
HELLO_SOMETHING = Hello{ 0 } !
在程序里使用资源的方式如下:
System.out.println(MyMessages.HELLO_WORLD);
System.out.println(MyMessages.bind(MyMessages.HELLO_SOMETHING, " world " ));
System.out.println(MyMessages.bind(MyMessages.HELLO_SOMETHING, " world " ));
自动将工程的字符串导出到资源文件中:
右键工程名称>source>Externalize Strings...可自动完成以上步骤。