Java正在覆盖进程中的文件

Java正在覆盖进程中的文件,java,openssl,overwrite,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.ge

我正在尝试用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中执行相同的精确代码时,它确实会覆盖它。

可能发生了错误,但没有显示出来。尝试显示
错误流的输出

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}));

没有显示错误,即跳过while循环。
InputStream
是否显示任何内容?我得到java.io。FileInputStream@5bda13No. 这就是对象本身。您只需将上面的
getErrorStream
位替换为
getInputStream
即可查看输出。最初,我得到了一个键和一个IV,这是预期的,并且正是cmd输出的。但是当我再次运行它时,我没有得到任何结果,这意味着它不会覆盖?是否在命令、选项开关和参数之间插入空格?