晓呆同学 2020-06-01 11:36 采纳率: 100%
浏览 164
已采纳

哪位大神能帮把这段C语音的代码翻译成Java代码,跪谢!

int getMabBuf(char* fileName, char* mabBuf)
{
    char sBlock[256+1];
    FILE *pfFileI;
    struct stat fbuf;
    if(stat(fileName,&fbuf) < 0)
    {
        return -1;
    }
    if ((pfFileI = fopen(fileName, "r")) == NULL)
    {
        return -2;
    }
    while (!feof(pfFileI))
    {
        memset(sBlock, 0, sizeof(sBlock));
        fread(sBlock, __BLOCKSIZE, 1, pfFileI);
        Do_XOR(mabBuf, sBlock, __BLOCKSIZE);
    }
    fclose(pfFileI);
    return 0;
}

void doXOR( char* deststr , char* source , int strlength )
{
int i = 0;
for( i = 0 ; i < strlength ; i++ )
{
deststr[i] ^= source[i];
}
}


#define __BLOCKSIZE 256

  • 写回答

1条回答 默认 最新

  • qybao 2020-06-01 14:54
    关注

    只是单纯的翻译代码

    public class Sample {
        public static final int __BLOCKSIZE = 256;
        public static int getMabBuf(String fileName, byte []mabBuf) {
            byte []sBlock = new byte[256+1];
            File pfFile = new File(fileName);
            if (! pfFile.exists()) {
                return -1;
            }
            try (FileInputStream fis = new FileInputStream(pfFile);) {
                while ((fis.read(sBlock, 0, __BLOCKSIZE)) != -1) {
                    doXOR(mabBuf, sBlock, __BLOCKSIZE);
                    Arrays.fill(sBlock, (byte)0);
                }
            } catch (Exception e) {
                return -2;
            }
            return 0;
        }
        public static void doXOR( byte []deststr , byte []source , int strlength ) {
            int i = 0;
            for( i = 0 ; i < strlength ; i++ ) {
                deststr[i] ^= source[i];
            }
        }
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 随机森林与房贷信用风险模型
  • ¥50 buildozer打包kivy app失败
  • ¥30 在vs2022里运行python代码
  • ¥15 不同尺寸货物如何寻找合适的包装箱型谱
  • ¥15 求解 yolo算法问题
  • ¥15 虚拟机打包apk出现错误
  • ¥15 用visual studi code完成html页面
  • ¥15 聚类分析或者python进行数据分析
  • ¥15 三菱伺服电机按启动按钮有使能但不动作
  • ¥15 js,页面2返回页面1时定位进入的设备