Thursday 20 February 2014

Bagaimana cara membuka file ? (Pemograman Java)

Berikut ini code untuk membuka sebuah file pada java..

 */
public class OpenFile {
    
     public void openFile(String path) {
        try {
            Desktop desktop = null;
            if (Desktop.isDesktopSupported()) {
                desktop = Desktop.getDesktop();
            }

            File f = new File(path);
            if (f.exists()) {
                desktop.open(f);

            } else {
                System.out.println("file tidak ditemukan");
            }
        } catch (IOException ioe) {
            System.out.println("error open");
          
        }
    }
     
     public static void main(String[] args) {
         String DATA_PATH = System.getProperty("user.home") + System.getProperty("file.separator") + "open.xlsx" ;
         
         OpenFile openFile= new OpenFile();
         openFile.openFile(DATA_PATH);
    }
    
}


Pertama kita membuat class yang bernama open file :

Source code nya :

 Tampilannya akan keluar seperti ini :
 Tampilan secara keseluruhan :




Sumber : http://adicodes.blogspot.com/

0 comments:

Post a Comment

Twitter Delicious Facebook Digg Stumbleupon Favorites More