从桌面用默认程序打开file

import java.awt.Desktop;
import java.io.*;

public static void main(String[] args) {
  // TODO Auto-generated method stub
  Desktop desktop = null;
  try{

    // Before more Desktop API is used, first check

    // whether the API is supported by this particular

    // virtual machine (VM) on this particular host.

    if (Desktop.isDesktopSupported()) {
      desktop = Desktop.getDesktop();
      desktop.open(new File("/home/illy/song.mp3"));
    }
   }
  catch (IOException e) {
    e.printStackTrace();
   }
}

 

你可能感兴趣的:(File)