[英]java.io.IOexception when initializing a process
When I compile this code, I get a java.io.IOexception error when initializing process p. 编译此代码时,初始化进程p时出现java.io.IOexception错误。 However, if I were to put it in a try catch block, I would get an error saying that this varible can't be found, when I try to use it on the line below.
但是,如果我将其放在try catch块中,当我尝试在下面的行中使用该变量时,会收到一条错误消息,指出找不到该变量。 Is there a way around the try catch block?
在try catch块周围有办法吗?
I am trying to run an executable file, that takes a par file as a parameter, and save the output of that executable file to a txt file. 我正在尝试运行一个以par文件作为参数的可执行文件,并将该可执行文件的输出保存到txt文件。
import java.io.*;
import java.util.*;
public class Class{
public static void main (String[] args)
{
ProcessBuilder pb = new ProcessBuilder("C:\\....\\c.exe", "C:\\.....\\w.par");
Process p = pb.start();
BufferedReader stdInput = new BufferedReader(new InputStreamReader(p.getInputStream()));
If you try to initialize a variable in a try-catch block it will not be "found" outside the scope of the try-catch block. 如果尝试在try-catch块中初始化变量,则不会在try-catch块的范围之外“找到”该变量。 Modify to look like this:
修改为如下所示:
import java.io.*;
import java.util.*;
public class Class{
public static void main (String[] args) {
ProcessBuilder pb = null;
Process p = null;
try {
ProcessBuilder pb = new ProcessBuilder("C:\\....\\c.exe", "C:\\.....\\w.par");
Process p = pb.start();
BufferedReader stdInput = new BufferedReader(newInputStreamReader(p.getInputStream()));
} catch (IOException | ProcessException e) {
System.err.println("Some error message");
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.