I have been studying Android players over the past few days. When I read the lyrics, I am always confused:
Today, I saw an article about file transcoding on the Internet, which completely solved my garbled problem, so that I don't have to manually transcode the LRC lyrics file, I would like to share with you this article (the principles of the conditions in the IF else are not very well understood. Please help me ):
Package com. qgmobile. utils;
Import java. Io. bufferedinputstream;
Import java. Io. bufferedreader;
Import java. Io. file;
Import java. Io. fileinputstream;
Import java. Io. ioexception;
Import java. Io. inputstreamreader;
/**
* Encoding format of the converted file
* @ Author yangchuxi
*
*/
Public class convertfilecode {
Public String converfile (string filepath ){
System. Out. println ("convertfilecode --------->" + filepath );
File file = new file (filepath );
Fileinputstream FCM = NULL;
Bufferedinputstream Bis = NULL;
Bufferedreader reader = NULL;
String text = "";
Try {
FS = new fileinputstream (File );
Bis = new bufferedinputstream (FCM );
Bis. Mark (4 );
Byte [] first3bytes = new byte [3];
// System. Out. println ("");
// Locate the first three bytes of the document and automatically determine the document type.
Bis. Read (first3bytes );
Bis. Reset ();
If (first3bytes [0] = (byte) 0xef & first3bytes [1] = (byte) 0xbb
& First3bytes [2] = (byte) 0xbf) {// UTF-8
Reader = new bufferedreader (New inputstreamreader (BIS, "UTF-8 "));
} Else if (first3bytes [0] = (byte) 0xff
& First3bytes [1] = (byte) 0xfe ){
Reader = new bufferedreader (
New inputstreamreader (BIS, "Unicode "));
} Else if (first3bytes [0] = (byte) 0xfe
& First3bytes [1] = (byte) 0xff ){
Reader = new bufferedreader (New inputstreamreader (BIS,
"Utf-16be "));
} Else if (first3bytes [0] = (byte) 0xff
& First3bytes [1] = (byte) 0xff ){
Reader = new bufferedreader (New inputstreamreader (BIS,
"Utf-16le "));
} Else {
Reader = new bufferedreader (New inputstreamreader (BIS, "GBK "));
}
String STR = reader. Readline ();
While (STR! = NULL ){
TEXT = text + STR + "/N ";
STR = reader. Readline ();
}
System. Out. println ("text" + text );
} Catch (exception e ){
E. printstacktrace ();
} Finally {
If (FS! = NULL ){
Try {
FCM. Close ();
} Catch (ioexception e ){
E. printstacktrace ();
}
}
If (Bis! = NULL ){
Try {
Bis. Close ();
} Catch (ioexception e ){
E. printstacktrace ();
}
}
}
Return text;
}
}