简体   繁体   English

Java正在覆盖文件

[英]Java overwriting file in process

I am trying to overwrite a file in Java. 我正在尝试覆盖Java中的文件。 The problem is the overwriting is done within an OpenSSl process. 问题是重写是在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();
        }

Why the -out parameter does not get overwritten? 为什么-out参数不会被覆盖? When I execute the same exact code in cmd.exe it does overwrite it. 当我在cmd.exe中执行相同的确切代码时,它会覆盖它。

It's possible that an error is occurring but not being displayed. 可能发生了错误但未显示。 Try displaying the output of the ErrorStream : 尝试显示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);
}

Also add this to verify they the array is what you think it should be: 还要添加此内容以验证数组是否符合您的想法:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM