无法使用java命令行打开PDF文件 [英] Unable to open PDF file using java command line

查看:352
本文介绍了无法使用java命令行打开PDF文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使用命令行参数作为

I am trying to open a PDF file from java using the command line argument as

String command = "cmd /c start AcroRd32.exe \"" + dir + "\"";

但是我得到一个错误,当文件将自动打开

But i am getting an error when the file will be automatically opened as

"Windows cannot find 'acroRd32.exe'. Please make sure you typed the correct name."

但是我可以手动打开它,而不使用命令行/ java。

However i am able to open it manually without using the command line/java.

请帮助我。

推荐答案

我强烈建议你这样做方式

I strongly recommend that you do it this way instead.

java.io.File file = new java.io.File("c:/some/file.pdf");
java.awt.Desktop.open(file);

如果您还想运行AcroRd32.exe(或其他命令 ProcessBuilder ,具有类似这样的内容 -

If you still want to run "AcroRd32.exe" (or some other "command") use a ProcessBuilder, with something like this -

ProcessBuilder pb = new ProcessBuilder("AcroRd32.exe", dir);
Process p = pb.start();

这篇关于无法使用java命令行打开PDF文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆