In some cases, such as when the file operations, especially in a Chinese document, will require the use GBK format, then read and write files, may appear garbled Chinese
- Resource files garbled
- Garbled file contents
Garbled resource file:
solve:
= PROPER PropertiesUtil new new PropertiesUti () String STR = new new String (proper.getValue ( "destFileName" ) .getBytes ( "ISO-8859-1"), "GBK"); // remove the contents of the resource file, then encoded change
Garbled contents of the file:
Operating files Chinese content, can not, can not or can not be converted to the encoding format stream read and write
solve:
// input stream the BufferedReader in = in = new new the BufferedReader ( new new the InputStreamReader ( new new the FileInputStream (File), "GBK" )); // read the entire contents of the file (file in the same format and content, containing wrap) the while ((Line in.readLine = ()) =! null ) { String strTemp = line.replace (oldstr, newStr); sb.append (strTemp + "\ n-" ); } // output stream BufferedWriter, OUT = new new BufferedWriter, ( new new the OutputStreamWriter ( new new FileOutputStream (File), "GBK" )); //Write to file out.write (sb.toString ());