您的位置:首页 > 编程语言 > Java开发

java 程序中打开文件和文件夹

2011-10-10 22:33 267 查看
打开文件

//打开工具的路径及名字

String toolsPath = "C:/WINDOWS/system32/notepad.exe ";

//被打开文件的路径及名字

String fileName = "test.txt";

try {

Runtime.getRuntime().exec(toolsPath+fileName);

} catch (IOException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}


打开文件夹

try {

String[] cmd = new String[5];

String url = "C:/input";

cmd[0] = "cmd";

cmd[1] = "/c";

cmd[2] = "start";

cmd[3] = " ";

cmd[4] = url;

Runtime.getRuntime().exec(cmd);

} catch (IOException e) {

e.printStackTrace();

}


或者

Runtime.getRuntime().exec("cmd /c start C:/input");
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐