java 程序中打开文件和文件夹
打開文件
//打開工具的路徑及名字
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");
版權聲明:本文為博主原創(chuàng)文章,未經(jīng)博主允許不得轉(zhuǎn)載。
轉(zhuǎn)載于:https://www.cnblogs.com/wangicter/archive/2011/10/10/4767415.html
總結
以上是生活随笔為你收集整理的java 程序中打开文件和文件夹的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 设计模式——原型模式
- 下一篇: .读取excel表格(JAVA)