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歌词用的

解决方案 »

  1.   

    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解压,需要专门的解压库
    }我帮你把数据读取这块写了,zip解压这块需要你找个解码库去解码。
    const char *pszFilePath : 为文件的绝对路径+文件名LZ如果没有点C/C++基础的话,估计也不好整合进去你的代码。手上没有linux,也没有max ox,这段代码是windows上的编译的,纯标准C代码,应该是通用的。
      

  2.   


    char *pTop = new char[4];
    char *pFileData = new char[nFileLength-4];
    处理完了,记得delete.