JAva呼び出しコンピュータ表示ドキュメント

2150 ワード

 
import java.awt.Desktop; 
import java.io.File; 
import java.io.IOException; 
 
/**
 * Java              
 * @see            ,       
 * @create Apr 23, 2013 1:00:37 AM
 * 
 */ 
public class OpenLocalFile { 
    public static void main(String[] args) throws IOException { 
       // useAWTDesktop(); 
        useCMDCommand(); 
        //useLocalCommand(); 
    } 
     
     
    /**
     *   java.awt.Desktop  
     * @see                 
     */ 
    private static void useAWTDesktop() throws IOException{ 
        Desktop.getDesktop().open(new File("..\\BaoDing_Shoop\\              .doc")); 
    } 
     
     
    /**
     *   cmd    
     * @see WPS  --------Runtime.getRuntime().exec("cmd /c start wps")
     * @see WPS  --------Runtime.getRuntime().exec("cmd /c start et")
     * @see WPS  --------Runtime.getRuntime().exec("cmd /c start wpp")
     * @see Office Word---Runtime.getRuntime().exec("cmd /c start winword")
     * @see Office Excel--Runtime.getRuntime().exec("cmd /c start excel")
     */ 
    private static void useCMDCommand() throws IOException{ 
        //                ,         
        //Runtime.getRuntime().exec("cmd /c start D:/mylocal/    .xls");  
        //(  '  ' 'Win+R',    'cmd /?'      )  
        Runtime.getRuntime().exec(new String[]{"cmd.exe", "/c", "G:\\java\\BaoDing_Shoop\\              .doc"}); 
    } 
     
     
    /**
     *           
     * @see                ,       ..                
     */ 
    private static void useLocalCommand() throws IOException{ 
        String etCommand = "D:/Program Files/WPS/8.1.0.3526/office6/et.exe"; 
        String filePath = "D:/mylocal/    .xls"; 
        Runtime.getRuntime().exec(etCommand + " " + filePath); 
    } 
}