怎么打开PDF文件(在类中调用Acrobat打开)? 你可以在www.lowagie.com/iText找到解决这个问题的控件类.很棒的.enjoy ! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 /** * 打开 PDF 文件 */ public class OpenPDF { public static void main(String[] args) { String cmd = "cmd"; if(System.getProperty("os.name").equals("Windows 98")) { System.out.println("Your OS is Win98"); cmd="command"; } String cmdPDF = "\"C:\\Program Files\\Adobe\\Acrobat 5.0\\Reader\\AcroRd32.exe\""; String filePDF = "E:\\电子文档\\JBuiler开发人员指南\\01.pdf"; String filePDF1 = "E:\\电子文档\\C# 教程\\01.pdf"; try{ Runtime.getRuntime().exec(cmd + " /c " + cmdPDF + " " + filePDF1); System.out.println(cmd + " /c " + cmdPDF + " " + filePDF1); System.out.println("OK, Success!"); } catch(Exception e){System.out.println(" Error of Openning File!");} }}/// end! 请教DainelLee,你用的什么IDE? 我用的是Eclipse,上面这段代码运行不了,请帮忙在你的IDE里调试一下,谢谢! Runtime.getRuntime().exec(cmd + " /c " + cmdPDF + " " + filePDF);上面这句代码出错 我是用的 jdk1.4.2 编译的,在我的机器(win 2000)能正常运行;^_^ 不好意思,我这边没有安装ide环境你是编译都不通过了?报什么错误啊? 谢谢DainelLee,已经调试通过了。 :)原因在我刚才改了这个代码:equals("Windows 98")--》equals("Windows 2000"), 在WIN2000下打开程序应该还是用 ”cmd “ 命令,现在明白了,多谢!!! :) 不好意思,再问一个问题:关于这个路径:C:\\Program Files\\Adobe\\Acrobat 5.0\\Reader\\AcroRd32.exe\在这段代码中是硬编码,怎么自动获得这个值,因为程序要在不同的机器上运行,甚至Mac机器 :) 判断两字符是否相等 Ask a problem about "list" 原始类型int float等 有没有像c++一样的引用& 加密算法怎么写?刚学,不懂,请大家多指教 求助:一段鼠标事件的代码老是不能编译,帮帮忙! 求救 JB中是不是不能使用断言,直接就提示语法错。有没有其它方法? 关于JAVA的类的定义格式解释? jbuilder编辑器问题,光标在前,而输入的字符在后,如何解决 今之江湖,谁才是一等一的JAVA高手,过来看招 做聊天室,用Socket好?还是DatagramSocket呢? 汉诺塔问题分析过程。
* 打开 PDF 文件
*/
public class OpenPDF {
public static void main(String[] args) {
String cmd = "cmd";
if(System.getProperty("os.name").equals("Windows 98")) {
System.out.println("Your OS is Win98");
cmd="command";
}
String cmdPDF = "\"C:\\Program Files\\Adobe\\Acrobat 5.0\\Reader\\AcroRd32.exe\"";
String filePDF = "E:\\电子文档\\JBuiler开发人员指南\\01.pdf";
String filePDF1 = "E:\\电子文档\\C# 教程\\01.pdf";
try{
Runtime.getRuntime().exec(cmd + " /c " + cmdPDF + " " + filePDF1);
System.out.println(cmd + " /c " + cmdPDF + " " + filePDF1);
System.out.println("OK, Success!");
}
catch(Exception e){System.out.println(" Error of Openning File!");}
}
}/// end!
上面这句代码出错
原因在我刚才改了这个代码:equals("Windows 98")--》equals("Windows 2000"), 在WIN2000下打开程序应该还是用 ”cmd “ 命令,现在明白了,多谢!!! :)