United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
JDK-6764271 : Desktop.open(File) does not work reliably on Windows

Details
Type:
Bug
Submit Date:
2008-10-27
Status:
Open
Updated Date:
2011-04-28
Project Name:
JDK
Resolved Date:
Component:
client-libs
OS:
linux
Sub-Component:
java.awt
CPU:
x86
Priority:
P4
Resolution:
Unresolved
Affected Versions:
6u10
Targeted Versions:

Related Reports

Sub Tasks

Description
Run this in XP sp2:

---%<---
import java.awt.Desktop;
import java.io.File;
public class OpenInSystem {
    public static void main(String[] args) throws Exception {
        File f = File.createTempFile("something", "txt");
        System.err.println(f);
        Desktop.getDesktop().open(f);
    }
}
---%<---

I get:

---%<---
java version "1.6.0_10"
Java(TM) SE Runtime Environment (build 1.6.0_10-b33)
Java HotSpot(TM) Client VM (build 11.0-b15, mixed mode, sharing)
C:\DOCUME~1\dev\LOCALS~1\Temp\something27450txt
Exception in thread "main" java.io.IOException: Failed to open file:/C:/DOCUME~1/dev/LOCALS~1/Temp/something27450txt. Error message: The parameter is incorrect.

        at sun.awt.windows.WDesktopPeer.ShellExecute(WDesktopPeer.java:59)
        at sun.awt.windows.WDesktopPeer.open(WDesktopPeer.java:36)
        at java.awt.Desktop.open(Desktop.java:254)
        at OpenInSystem.main(OpenInSystem.java:7)
---%<---

It is not clear what the message "The parameter is incorrect." is referring to exactly; the parameter is the path to an existing file, and the URI looks to be fine.

But if "txt" is replaced with ".txt" then Notepad is opened on the file as expected. It is not surprising that Windows has no application ready to open a file without extension, but the error message is inappropriate, and I would at least expect a regular application chooser dialog, as if you had double-clicked the file in Explorer.

Calling getCanonicalPath() does not help.

                                    

Comments



Hardware and Software, Engineered to Work Together