如何将文件分割为java中的块?

时间:2013-09-13 21:33:02

标签: java cryptography public-key-encryption

我尝试通过java生成代码,能够从文件中读取100 kb然后将文件分成块,每个块有256位或32位也希望将每个块转换为二进制格式或整数格式以下是它 我需要任何建议

public static void main(String[] args) {

    ReadFileExample newclass = new ReadFileExample();
    System.out.println("-----------Wellcome in ECC ENCRYPTION NEW--------");
    File clearmsg = new File("F:/java_projects/clearmsg.txt");
    File ciphermsg = new File("F:/java_projects/ciphermsg.txt");
    byte[] block = new byte[32];        
    try {
        FileInputStream fis = new FileInputStream(clearmsg);
        FileOutputStream fos = new FileOutputStream(ciphermsg);
        CipherOutputStream cos = new CipherOutputStream(fos);               
        System.out.println("Total file size to read (in bytes) : "
            + fis.available());
        int i;
        while ((i = fis.read(block)) != -1) {
            System.out.println(block);
            fos.write(block, 0, i);
        }
        fos.close();

0 个答案:

没有答案