简体   繁体   English

初始化进程时出现java.io.IOexception

[英]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.

相关问题 Process Builder java.io.IOException错误= 2 - Process Builder java.io.IOException error=2 java.io.IOException java - java.io.IOException java MapReduce 中的 java.io.IOException - java.io.IOException in MapReduce 编译Java代码时出现未报告的异常java.io.IOException - Unreported exception java.io.IOException when compiling Java code java.io.IOException:进程无法访问文件,因为另一个进程锁定了一部分 - 在 Windows 中使用 IOUtils.copyLarge() 时 - java.io.IOException: The process cannot access the file because another process has locked a portion - when using IOUtils.copyLarge() in Windows java.io.IOException:在Andoid上使用相机时权限被拒绝? - java.io.IOException: Permission denied when using Camera on Andoid? 什么时候抛出“java.io.IOException:Connection reset by peer”? - When is "java.io.IOException:Connection reset by peer" thrown? 声明日志文件的路径时出现java.io.IOException - java.io.IOException when declaring path to log file 什么时候出现java.io.IOException:用Netty抛出的对等重置连接? - When is java.io.IOException: Connection reset by peer thrown with Netty? java.io.IOException:在ByteArrayInputStream中传递时,不是GZIP格式 - java.io.IOException: Not in GZIP format when passing in ByteArrayInputStream
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM