Java打开(.word,.txt,.pdf)文件

发布时间:2019-05-16 19:52:33   来源:文档文库   
字号:

[size=x-large] 

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

Rundll32.exe DLLname,Functionname [Arguments] 

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

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

rundll32 url.dll FileProtocolHandler  



下面是通过JFileChoose对话框,选中一个文件之后,打开所选的文件,像直接双击打开文件一样的,打开选中的文件 



  

Java代码  

1. JFileChooser chooseFile = new JFileChooser();  

2. FileFilter filter = new FileFilter() {  

3.   

4.     //要过滤的文件  

5.     public boolean accept(File f) {  

6.         //显示的文件类型  

7.         if (f.isDirectory()) {  

8.             return true;  

9.         }  

10.         //显示满足条件的文件     

11.         return f.getName().endsWith(".txt") || f.getName().endsWith(".java");  

12.     }  

13.   

14.     /**   

15.      * 这就是显示在打开框中   

16.      */  

17.     public String getDescription() {  

18.   

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

20.     }  

21. };  

22.   

23. FileFilter filter1 = new FileFilter() {  

24.   

25.     public boolean accept(File f) {  

26.         if (f.isFile()) {  

27.             return true;  

28.         }  

29.         //显示满足条件的文件     

30.         return f.getName().endsWith(".xls");  

31.     }  

32.   

33.     /**   

34.      * 这就是显示在打开框中   

35.      */  

36.     public String getDescription() {  

37.         return "*.xls";  

38.     }  

39. };  

40.   

41.    

42. chooseFile.addChoosableFileFilter(filter);  

43. chooseFile.addChoosableFileFilter(filter1);  

44. int open = chooseFile.showOpenDialog(this);  

45. if (open == JFileChooser.APPROVE_OPTION) {  

46.     File f = chooseFile.getSelectedFile();  

47.     Runtime runtime = Runtime.getRuntime();  

48.     try{  

49.         System.out.println(f.getAbsolutePath());  

50.         //打开文件  

51.         runtime.exec("rundll32 url.dll FileProtocolHandler "+f.getAbsolutePath());  

52.     }catch(Exception ex){  

53.         ex.printStackTrace();  

54.     }  

55.      

56. }  

[/size]

本文来源:https://www.2haoxitong.net/k/doc/ae4269ef172ded630b1cb68f.html

《Java打开(.word,.txt,.pdf)文件.doc》
将本文的Word文档下载到电脑,方便收藏和打印
推荐度:
点击下载文档

文档为doc格式