如何在java中发布进程资源

时间:2015-10-09 05:22:03

标签: java

如何发布流程资源??

import java.io.BufferedReader;
 import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.util.StringTokenizer;
public class RuntimeSample{
public RuntimeSample() {
}
private void execCmd1() throws IOException {
InputStream in = null;
Process process = null;
String[] cmd = { "java", "-version" };
try {
process = Runtime.getRuntime().exec(cmd);
in = process.getInputStream();
} catch (Exception e) {
e.printStackTrace();
} finally {
if (in != null) {
in.close();
}}} 
private void execCmd2() throws IOException {
Process process = null;
String[] cmd = { "java", "-version" };
try {
process = Runtime.getRuntime().exec(cmd);
} catch (Exception e) {
e.printStackTrace();
} finally {
}} }

为什么它抛出process.getError流没有关闭,我试图通过使用以下

来关闭进程资源
if (process != null) {
 process.getInputStream().close();
 process.getOutputStream().close();
 process.getErrorStream().close();

即使它显示process.getError流也没有关闭。我知道原因是它显示流未关闭以及如何关闭流程资源。提前谢谢

0 个答案:

没有答案