Am using the following code snippet to open a file,
if (Desktop.isDesktopSupported()) {
try {
Desktop desktop = Desktop.getDesktop();
File myFile = new File(fileName);
desktop.open(myFile);
} catch (IOException ex) {}
}
if the file i try to open is of normal .txt or .pdf any such file types i can able to open the file.
But in some cases,
As shown above the Type of file is File , in this scenario the file is not opened.
if i manually open this File type file i get open with window and using a text editor i am able to open it.
How should i handle this in java? Please help..
Windows says the type of the file is "file" when there is no extension. This is why there is no default opener, and that is why Java doesn't open the file properly.
You can either rename the file and give it an extension, or use Java to directly execute the program you want to open the file with.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.