tags:

views:

24

answers:

1

I am trying to open a text file from an application run on UNIX using java.awt.Desktop 's open() method. If the file to be opened contains "From:" at its beginning, the API, fails by throwing an IOException.

Caused by: java.io.IOException: Failed to show URI:file:/filename.txt
    at sun.awt.X11.XDesktopPeer.launch(XDesktopPeer.java:75)
    at sun.awt.X11.XDesktopPeer.open(XDesktopPeer.java:43)
    at java.awt.Desktop.open(Desktop.java:254) 

Removing the colon (:) after "From" in the content makes it work though. The problem does not occur in Windows. Any light on this ?

A: 

On windows, it's pretty easy: windows chooses the right fie viewer/editor just based on the filename or even only based on the extension. So a *.txt file will always be opened with notepad (unless you installed a real editor and changed the binding...)

Not knowing but guessing: UNIX is more intelligent and can look into text files to guess the right application. And in this case, the guess for a file starting with "From:" is email so the current OS tries to start the application, that is registered for EMails with this text file. Either the application doesn't start or the file just can't be read.

You should be able to simulate it if you fire up a navigtor and doubl-click on the text files icon. The starting application should be the same as the one that will be spawned with the open() call.

Andreas_D
Thanks Andreas. Your thoughts helped to debug.
JavaGeek
FYI: on double clicking file with 'From:' --The filename "TestDoc.txt" indicates that this file is of type "Plain text document". The contents of the file indicate that the file is of type "Email message/mailbox". If you open this file, the file might present a security risk to your system.Do not open the file unless you created the file yourself, or received the file from a trusted source. To open the file, rename the file to the correct extension for "Email message/mailbox", then open the file normally. Alternatively, use the Open With menu to choose a specific application for the file.
JavaGeek
Ah - so the security setting might prevent from opening the file in this (special) case.
Andreas_D