读取ZipDecryptInputStream表单并将其写入OutputStream

时间:2016-10-12 03:16:32

标签: java inputstream

public void decrypt(String inputFile,String password){

    ZipDecryptInputStream zipDecrypt = null;
    try {
        zipDecrypt = new ZipDecryptInputStream(new FileInputStream(
                inputFile), password);
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }

    File file = new File("outouttfile.tsv");
    OutputStream fop = null;
    try {
        fop = new FileOutputStream(file);
    } catch (FileNotFoundException e1) {
        e1.printStackTrace();
    }

    try {

        byte[] buffer = new byte[1024];
        int bytesRead;      
        while ((bytesRead = zipDecrypt.read(buffer)) != -1) {
            fop.write(buffer, 0, bytesRead);
            System.out.println("Written");
        }
    } catch (IOException e) {
        e.printStackTrace();
    }

}

我的while循环变为无限循环,即使只读了一次也不会停止读取文件。知道为什么吗?

0 个答案:

没有答案