------ Solution ---------------------------------------------------------- respectively call the following two methods to see what is output
Java code
Public static void readgbkcodingfile (string filename) {// read the content of the GBK file bufferedreader BR = NULL; try {BR = new bufferedreader (New inputstreamreader (New fileinputstream (filename ), "GBK"); string line = NULL; while (line = BR. readline ())! = NULL) {system. Out. println (line) ;}} catch (exception e) {}finally {try {If (BR! = NULL) Br. close ();} catch (ioexception e) {}} public static void readutfcodingfile (string filename) {// read the contents of the UTF-8 file bufferedreader BR = NULL; try {BR = new bufferedreader (New inputstreamreader (New fileinputstream (filename), "UTF-8"); string line = NULL; while (line = BR. readline ())! = NULL) {system. Out. println (line) ;}} catch (exception e) {}finally {try {If (BR! = NULL) Br. Close ();} catch (ioexception e) {}}------ solution ---------------------------------------------------------- if you want to convert the file format, try the following two methods:
Java code
Public static void convertgbkfiletoutffile (string srcfilename, string destfilename) {// convert the GBK file to the UTF file bufferedreader BR = NULL; bufferedwriter BW = NULL; try {BR = new bufferedreader (New inputstreamreader (New fileinputstream (srcfilename), "GBK"); BW = new bufferedwriter (New outputstreamwriter (New fileoutputstream (destfilename ), "UTF-8"); string line = NULL; while (line = BR. readline ())! = NULL) {BW. Write (line); BW. newline () ;}} catch (exception e) {} finally {try {If (BR! = NULL) Br. Close (); If (BW! = NULL) BW. close ();} catch (ioexception e) {}} public static void convertutffiletogbkfile (string srcfilename, string destfilename) {// convert the GBK file to the UTF file bufferedreader BR = NULL; bufferedwriter BW = NULL; try {BR = new bufferedreader (New inputstreamreader (New fileinputstream (srcfilename ), "UTF-8"); BW = new bufferedwriter (New outputstreamwriter (New fileoutputstream (destfilename), "GBK"); ST Ring Line = NULL; while (line = Br. Readline ())! = NULL) {BW. Write (line); BW. newline () ;}} catch (exception e) {} finally {try {If (BR! = NULL) Br. Close (); If (BW! = NULL) BW. Close () ;}catch (ioexception e ){}}}
Source: http://www.myexception.cn/j2se/38591.html
According to my own test, "GBK" is case sensitive.