Java正在覆盖文件

时间:2013-05-28 14:31:59

标签: java openssl overwrite

我正在尝试用Java覆盖文件。问题是覆盖是在OpenSSl进程中完成的。

Runtime rt = Runtime.getRuntime();
         try {
            rt.exec(new String[]{"cmd.exe","/c","openssl enc -aes-256-cbc -nosalt -in \"" + source.getAbsolutePath()+
                    "\" -out \"" + source.getAbsolutePath()+".enc\""  + " -p -pass pass:" + Key});

        } catch (IOException e) {
            e.printStackTrace();
        }

为什么-out参数不会被覆盖?当我在cmd.exe中执行相同的确切代码时,它会覆盖它。

1 个答案:

答案 0 :(得分:0)

可能发生错误但未显示错误。尝试显示ErrorStream

的输出
Process process = rt.exec(...);

BufferedReader error = new BufferedReader(new InputStreamReader(process.getErrorStream()));
String errorLine = null;
while ((errorLine = error.readLine()) != null) {
   System.out.print(errorLine);
}

同时添加此项以验证它们是否符合您认为应该是:

System.out.print(Arrays.toString(new String[]{"cmd.exe","/c","openssl enc -aes-256-cbc -nosalt -in \"" + source.getAbsolutePath()+
                    "\" -out \"" + source.getAbsolutePath()+".enc\""  + " -p -pass pass:" + Key}));