使用java代码打开chm格式的帮助文档

package com.guan.code20160405;

import java.io.File;

import java.io.IOException;

public class OpenHelpFile {

public static void main(String[] args) {

/**

*我把五子棋文档1.0.chm放在和项目同目录下的projectFile文件夹下

*/

String ch1="/";

String ch2="//";

//找到项目的根路径

String contextPath = System.getProperty("user.dir");

File file=new File(contextPath);

String p = file.getParent();

file = new File(p + "/projectFile");

System.out.println("path===="+file.getPath());

System.out.println("parent==="+file.getParent());

String helpFilePath = p + "/projectFile/五子棋文档1.0.chm";

try {

//hh.exe是Windows系统中允许chm文件的程序

Runtime.getRuntime().exec("hh.exe "+helpFilePath.replaceAll(ch1,ch2));

} catch (IOException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

}

}

运行,成功打开“五子棋文档1.0.chm”文件。