Properties is a class provided by java to solve key-value pairs stored in files. It inherits HashTable and can process java standard configuration files.
However, when Properties reads text from a file stream, getProperty (key) is decoded using a ISO8859-1, so garbled characters are read from Chinese, the read string needs to be encoded back from the ISO8859-1 and decoded in the text encoding format.
String s = new String (properties. getProterty (key). getBytes [] ("ISO8859-1"), "UTF-8 ");
UTF-8 is its own encoding format.
Note: In Properties. load
Java code
FileInputStream isr = new FileInputStream (savePath );
Properties props = new Properties ();
Props. load (isr );
Note: isr must be a file byte stream, not a volume stream. Otherwise, garbled characters may occur. (Or there is a solution, but I haven't found it yet !)
Java code
OutputStreamWriter osw = new OutputStreamWriter (new FileOutputStream (savePath), "UTF-8 ");
Props. store (osw, "This is the System Config file, Please don't delete or modify it! ");
Author "wangboak"