RunTime类,后台快速打开浏览器
cmd命令是java程序員最開(kāi)始學(xué)習(xí)java的時(shí)候使用的工具,那么在以后的工作中我們還能用他玩些什么呢?
大家都知道cmd.exe文件是在system32文件夾下面的文件,那么同樣在system下的文件我們是否可以操作呢?
接下來(lái)看看java中RunTime類(lèi)的玩法吧。
打開(kāi)計(jì)算器
package com.xxg.action;
import java.io.IOException;
public class action {
public static void main(String[] args) {
Runtime rt=Runtime.getRuntime();
try {
rt.exec("calc");
} catch (IOException e) {
// TODO 自動(dòng)生成的 catch 塊
e.printStackTrace();
}
}
}
打開(kāi)記事本
package com.xxg.action;
import java.io.IOException;
public class action {
public static void main(String[] args) {
Runtime rt=Runtime.getRuntime();
try {
rt.exec("notepad");
} catch (IOException e) {
// TODO 自動(dòng)生成的 catch 塊
e.printStackTrace();
}
}
}
打開(kāi)一個(gè)網(wǎng)站
package com.xxg.action;
import java.io.IOException;
public class action {
public static void main(String[] args) {
Runtime rt=Runtime.getRuntime();
try {
rt.exec("rundll32 url.dll,FileProtocolHandler " + "http://xiangxunguo.com");
} catch (IOException e) {
// TODO 自動(dòng)生成的 catch 塊
e.printStackTrace();
}
}
}
是不是很好玩呢,也可以通過(guò)這個(gè)打開(kāi)具體的文件。
例如:
package com.xxg.action;
import java.io.IOException;
public class action {
public static void main(String[] args) {
Runtime rt=Runtime.getRuntime();
try {
rt.exec("rundll32 url.dll,FileProtocolHandler "+"E:\\cun\\easyUI_紅目香薰\\index.html");
} catch (IOException e) {
// TODO 自動(dòng)生成的 catch 塊
e.printStackTrace();
}
}
}
rundll32是執(zhí)行32位的dll程序
有些電腦是rundll,還有一些病毒是rundl132這個(gè)一定要分清,只要不是在system32下載的這個(gè)文件基本都屬于病毒。
希望能對(duì)大家有所幫助。
總結(jié)
以上是生活随笔為你收集整理的RunTime类,后台快速打开浏览器的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: io流文本文档的快速读取
- 下一篇: Ubuntu 16.04安装Tomcat