1. Java Processing internationalization fragments
Static
{
Logger.log (Level.info, "Start loading language environment");
Tacit consent to Chinese
locale = new locale (Utilsconstants.utils_language,
Utilsconstants.utils_country);
Messages = Resourcebundle.getbundle (Configfilepath.getpackagespath ()
+ utilsconstants.utils_base_res, locale);
}
public string GetMessage (string target)
{
Try
{
TODO auto-generated Method Stub
return messages.getstring (target);
} catch (MissingResourceException e)
{
Logger.log (Level.severe,
Messages.getstring ("Utils.message.log.NoKeyInFile")
+ "[" + Target + "]");
Return "";
}
}
2. Java read-write properties file
/**
* Initialize Load
*/
Static
{
Logger.log (Level.info, GetMessage ("Utils.message.log.startLoadFile"));
InputStream in = null;
Build Property File path
String FilePath = configfilepath.getfilepaths () + fileName;
Load Properties File
Try
{
in = new Bufferedinputstream (new FileInputStream (FilePath));
Properties.load (in);
Logger.log (Level.info, GetMessage ("Utils.message.log.endLoadFile"));
} catch (FileNotFoundException e)
{
TODO auto-generated Catch block
Logger.log (Level.severe,
GetMessage ("Utils.message.log.createFileStreamFail"), e);
} catch (IOException e)
{
TODO auto-generated Catch block
Logger.log (Level.severe,
GetMessage ("Utils.message.log.loadPropertyFileFail"), e);
} finally
{
Try
{
In.close ();
} catch (IOException e)
{
TODO auto-generated Catch block
Logger.log (Level.severe,
GetMessage ("Utils.message.log.closeFileStreamFail"), e);
}
}
}
@Override
public string ReadProperty (string key)
{
TODO auto-generated Method Stub
if (null = = Properties.getproperty (key))
{
Logger.log (Level.severe,
GetMessage ("Utils.message.log.propertyIsNull"));
}
return Properties.getproperty (key);
}
@Override
public boolean WriteProperty (string key, String value)
{
TODO auto-generated Method Stub
Properties.setproperty (key, value);
String FilePath = configfilepath.getfilepaths () + fileName;
OutputStream out = null;
Save Properties File
Try
{
out = new Bufferedoutputstream (new FileOutputStream (FilePath));
Properties.store (Out, "");
} catch (FileNotFoundException e)
{
TODO auto-generated Catch block
Logger.log (Level.severe,
GetMessage ("Utils.message.log.createFileStreamFail"), e);
} catch (IOException e)
{
TODO auto-generated Catch block
Logger.log (Level.severe,
GetMessage ("Utils.message.log.stroePropertyFileFail"), e);
} finally
{
Try
{
Out.close ();
} catch (IOException e)
{
TODO auto-generated Catch block
Logger.log (Level.severe,
GetMessage ("Utils.message.log.closeFileStreamFail"), e);
}
}
return false;
}
Java handles internationalization and reads the properties file code snippet