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

java 打开文件

2013-07-18 21:20 218 查看
windows系统提供了一个叫Rundll32.exe的文件,顾名思义,它的作用是执行DLL文件中的内部函数,这样在进程当中,只会有rundll32.exe,而不会有DLL后门的进程,这样,就实现了进程上的隐藏。rundll32.exe的具体使用方法如下:

Rundll32.exe DLLname,Functionname [Arguments]

DLLname为需要执行的DLL文件名;Functionname为前边需要执行的DLL文件的具体引出函数;[Arguments]为引出函数的具体参数。

结合url.dll和rundll32.exe,我们就可以通过在命令行中启动相应程序打开相应文档: 假设我有一个pdf文档,存放在c:\test.pdf 。打开命令行, 运行如下 命令:

rundll32 url.dll FileProtocolHandler

下面是通过JFileChoose对话框,选中一个文件之后,打开所选的文件,像直接双击打开文件一样的,打开选中的文件
JFileChooser chooseFile = new JFileChooser();
FileFilter filter = new FileFilter() {

//要过滤的文件
public boolean accept(File f) {
//显示的文件类型
if (f.isDirectory()) {
return true;
}
//显示满足条件的文件
return f.getName().endsWith(".txt") || f.getName().endsWith(".java");
}

/**
* 这就是显示在打开框中
*/
public String getDescription() {

return "*.txt,*.java";
}
};

FileFilter filter1 = new FileFilter() {

public boolean accept(File f) {
if (f.isFile()) {
return true;
}
//显示满足条件的文件
return f.getName().endsWith(".xls");
}

/**
* 这就是显示在打开框中
*/
public String getDescription() {
return "*.xls";
}
};

chooseFile.addChoosableFileFilter(filter);
chooseFile.addChoosableFileFilter(filter1);
int open = chooseFile.showOpenDialog(this);
if (open == JFileChooser.APPROVE_OPTION) {
File f = chooseFile.getSelectedFile();
Runtime runtime = Runtime.getRuntime();
try{
System.out.println(f.getAbsolutePath());
//打开文件
runtime.exec("rundll32 url.dll FileProtocolHandler "+f.getAbsolutePath());
}catch(Exception ex){
ex.printStackTrace();
}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: