java打开文件(Windows exe,应用文件exe,以及其他任何格式的文件)

使用java代码打开任何格式的文件

	public static void main(String[] args) throws IOException {  
		openWindowsExe();  
		openExe();  
		openFile();
	 }  
		  //用 Java 调用windows系统的exe文件,比如notepad,calc之类  
	public static void openWindowsExe() {  
		Runtime rn = Runtime.getRuntime();  
		Process p = null;  
		try {  
			String command = "notepad";  
			p = rn.exec(command);  
		} catch (Exception e) {  
			System.out.println("Error win exec!");  
		}  
	}  
		  //调用其他的可执行文件,例如:自己制作的exe,或是 下载 安装的软件.  
	public static void openExe() {  
		Runtime rn = Runtime.getRuntime();  
		Process p = null;  

		try {  
			p = rn.exec("\"D:/QQ.exe\"");  
		
		} catch (Exception e) {  
			System.out.println("Error exec!");  
		}  
	}  
		  
		  //打开其他任意格式的文件,比如txt,word等
	public static void openFile() {  
		Runtime rn = Runtime.getRuntime();  
		Process p = null;  
		String cmd="rundll32 url.dll FileProtocolHandler file://D:/help.doc ";
		try {  
			p = rn.exec(cmd);
		} catch (Exception e) {  
			System.out.println("Error exec!");  
		}  
	} 



版权声明:本文为angel_xiaa原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。