0
我試圖以這種方式來打開默認的程序.jpg文件:沒有應用程序與此操作的指定文件相關聯。錯誤
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
public class Test {
public static void main(String[] args) throws IOException {
File image = new File(System.getProperty("user.home") +
"/Desktop/project/XL-116/DATAFILE17.jpg");
try {
java.awt.Desktop.getDesktop().open(image);
} catch (FileNotFoundException ex) {
// .....
}
}
}
而且我得到這個錯誤:
Exception in thread "main" java.io.IOException: Failed to open C:\Users\khuda
Dad\Desktop\project\XL-116\DATAFILE17.jpg. Error message: No application is
associated with the specified file for this operation.
at sun.awt.windows.WDesktopPeer.ShellExecute(Unknown Source)
at sun.awt.windows.WDesktopPeer.open(Unknown Source)
at java.awt.Desktop.open(Unknown Source)
at Test.main(Test.java:9)
而且我已經檢查了默認程序。沒有錯。那麼問題是什麼?
我同意:「IOException - 如果指定的文件沒有關聯的應用程序或關聯的應用程序無法啓動」 – dbalakirev