public class QQStarter {
Runtime r = Runtime.getRuntime();
/**声明需要启动的文件名称*/
String targetFileName = "QQScLauncher.exe";
/**
* QQScLauncher.exe
* @param dir
* @throws IOException
*/
public void read(File dir) throws IOException {
//遍历目录中的所有子文件(File)
File[] files = dir.listFiles();
if(files != null) {
for(File f:files) {
System.out.println(f.getAbsolutePath());
//判断当前File对象是否是一个标准文件
if(f.isFile() && f.getName().equals(targetFileName)) {
//启动文件
r.exec(f.getAbsolutePath());
System.exit(0);
}else {
read(f);
}
}
}
}
public static void main(String[] args) throws IOException {
QQStarter starter = new QQStarter();
//列出所有的可用文件系统的根(windows中指的是所有磁盘和光驱,linux/mac是 / )
File[] roots = File.listRoots();
for(File f:roots) {
starter.read(f);
}
}
}