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.
#open
method finds the specified default app to open the specified file but in .file
type there is no default app to open the file.You can only specify manually to open it in specific app.So if you set the default application that should open the .file
and you have to set the default application and choose default program to open the file and than run the program.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With