import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
public class KrcText
{
private static final char[] miarry = { '@', 'G', 'a', 'w', '^', '2', 't',
'G', 'Q', '6', '1', '-', 'Î', 'Ò', 'n', 'i' };
public static void main(String[] args) throws IOException
{
String filenm = "";//krc文件的全路径加文件名
System.out.println(new KrcText().getKrcText(filenm));
}
/**
*
* @param filenm krc文件路径加文件名
* @return krc文件处理后的文本
* @throws IOException
*/
public String getKrcText(String filenm) throws IOException
{
File krcfile = new File(filenm);
byte[] zip_byte = new byte[(int) krcfile.length()];
FileInputStream fileinstrm = new FileInputStream(krcfile);
byte[] top = new byte[4];
fileinstrm.read(top);
fileinstrm.read(zip_byte);
int j = zip_byte.length;
for (int k = 0; k < j; k++)
{
int l = k % 16;
int tmp67_65 = k;
byte[] tmp67_64 = zip_byte;
tmp67_64[tmp67_65] = (byte) (tmp67_64[tmp67_65] ^ miarry[l]);
}
String krc_text = new String(ZLibUtils.decompress(zip_byte), "utf-8");
return krc_text;
}
}
红色部分的这个方法,看看有木有办法转换成iphone上可以直接使用的。。多谢^^!~这个代码是解析krc歌词用的
------解决方案--------------------
- C/C++ code
void getKrcText(const char *pszFilePath){ char szMiarry[] = { '@', 'G', 'a', 'w', '^', '2', 't','G', 'Q', '6', '1', '-', 'Î', 'Ò', 'n', 'i' }; FILE *fp = ::fopen(pszFilePath, "rb"); ::fseek(fp, SEEK_SET, SEEK_END); int nFileLength = ::ftell(fp); ::fseek(fp, SEEK_SET, SEEK_SET); char *pTop = new char[4]; char *pFileData = new char[nFileLength-4]; ::fread(pTop, 1, 4, fp); int nRead = 0; for ( ; nRead < nFileLength - 4; ) { int nCurRead = ::fread(pFileData + nRead, 1, nFileLength - 4 - nRead, fp); nRead += nCurRead; } for ( int k = 0; k < nFileLength - 4; ++k ) { int j = k % 16; pFileData[k] ^= szMiarry[j]; } // zip解压,需要专门的解压库}