Berikut ini code untuk membuka sebuah file pada java..
/**
*
* @author adi nuralim
*/
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);
}
}
/**
*
* @author adi nuralim
*/
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);
}
}
No comments:
Post a Comment