1

我有这个程序。

try {
            Runtime rt = Runtime.getRuntime();
            //Process pr = rt.exec("cmd /c dir");
            Process pr = rt.exec("java -jar C:/sample/sample.jar D:/pdftest.pdf");
            BufferedReader input1 = new BufferedReader(new InputStreamReader(pr.getInputStream()));

            String line=null;

            while((line=input1.readLine()) != null) {
                System.out.println(line);
            }               

            int exitVal = pr.waitFor();
            System.out.println("Exited with error code "+exitVal);

        } catch(Exception e) {
            System.out.println(e.toString());
            e.printStackTrace();
        }

在这里, process pr 定义了一个命令。现在我的问题是,我想将“D:/pdftest.pdf”部分替换为类似的变量

String pdfvariable="D:/pdftest.pdf";

所以我应该能够将“D:/pdftest.pdf”的硬编码值替换为 pdfvariable。可能吗?谁能给我解释一下?谢谢

4

1 回答 1

1
String pdfvariable = "D:/pdftest.pdf";
Process pr = rt.exec("java -jar C:/sample/sample.jar " + pdfVariable);
于 2012-09-18T12:01:17.230 回答