allelopath
asked on
Desktop File operations not working
The code below does nothing. No file opened, no exception thrown.
What can I do to discover the problem?
It does execute the desktop.open(file) line.
Using JDK 1.16.0_81
Running Win XP
I'm running this from the Eclipse IDE.
Running the demo here:
http://java.sun.com/developer/technicalArticles/J2SE/Desktop/javase6/desktop_api/
the browse and mail functionality works, but not the file functionality, again same result, just nothing.
What can I do to discover the problem?
It does execute the desktop.open(file) line.
Using JDK 1.16.0_81
Running Win XP
I'm running this from the Eclipse IDE.
Running the demo here:
http://java.sun.com/developer/technicalArticles/J2SE/Desktop/javase6/desktop_api/
the browse and mail functionality works, but not the file functionality, again same result, just nothing.
package desktopdemo;
import java.awt.Desktop;
import java.io.File;
import java.io.IOException;
public class MyDesktopDemo {
public MyDesktopDemo() {
// have tried .txt, .rtf, .pptx all with no effect
String pathAndFileString = "C:\\my.pptx";
File file = new File(pathAndFileString);
if (Desktop.isDesktopSupported()) {
Desktop desktop = Desktop.getDesktop();
if (desktop.isSupported(Desktop.Action.OPEN )) {
try {
System.out.println("desktop.open(" + pathAndFileString + ")"); // gets here
desktop.open(file); // but nothing happens
} catch (IOException e1) {
e1.printStackTrace();
}
}
else {
System.out.println("Desktop.Action.OPEN not supported");
}
}
else {
System.out.println("Desktop not supported");
}
}
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new MyDesktopDemo();
}
});
}
}
ASKER
The file is definitely there. If I change the name to a non-existent file, eg. "myZZZ.pptx", then it throws an exception. I've also tried files with various extensions, like txt, pdf, rtf, with no difference.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
If the answer to that is yes, you might like to try jdic: it does much the same thing, and i'd guess (i have to guess since there's probably no native source for what you're currently using.
Looking at it and running it could give you some clues
https://jdic.dev.java.net
Looking at it and running it could give you some clues
https://jdic.dev.java.net
does the file open ok if you double click on it?
ASKER
>>does the file open ok if you double click on it?
yes
yes
> String pathAndFileString = "C:\\my.pptx";
does it still fail if you change that to:
String pathAndFileString = "/my.pptx";
does it still fail if you change that to:
String pathAndFileString = "/my.pptx";
Can you run your code from the command line (i.e. not in Eclipse) and tell us what you get?
Hi Allelopath,
When I change the file extension to 'abc', and got the error on the console windows:
Failed to open file:/C:/my.abc. Error message: No application is associated with the specified file for this operation.
And change the file to 'my.txt'. It's open ok, with the msg on the console windows:
desktop.open(C:\my.txt)
Maybe there's no application that is associated to your file?
>>Maybe there's no application that is associated to your file?
There is, or it wouldn't open on double-click
There is, or it wouldn't open on double-click
May well be a bug, there are a few Desktop on XP bugs in the db
ASKER
objects:
/my.pptx makes no differences. good idea though.
/my.pptx makes no differences. good idea though.
what service pack?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
eclipse (or not) won't make a difference
It could well make a difference to perceived errors
so please enlighten us with why?
ASKER
Microsoft Windows
Version 5.1 (Build 2600.xpsp_sp3_gdr100427-16 36: Service Pack 3)
Version 5.1 (Build 2600.xpsp_sp3_gdr100427-16
ASKER
CEHJ:
To assure there were no exceptions being missing, I added code to catch any exception:
To assure there were no exceptions being missing, I added code to catch any exception:
package desktopdemo;
import java.awt.Desktop;
import java.io.File;
import java.io.IOException;
public class MyDesktopDemo {
public MyDesktopDemo() {
// have tried .txt, .rtf, .pptx all with no effect
String pathAndFileString = "/my.txt";
File file = new File(pathAndFileString);
if (Desktop.isDesktopSupported()) {
Desktop desktop = Desktop.getDesktop();
if (desktop.isSupported(Desktop.Action.OPEN )) {
try {
System.out.println("desktop.open(" + pathAndFileString + ")"); // gets here
desktop.open(file); // but nothing happens
} catch (IOException e1) {
e1.printStackTrace();
} catch (Exception e1) {
e1.printStackTrace();
} }
else {
System.out.println("Desktop.Action.OPEN not supported");
}
}
else {
System.out.println("Desktop not supported");
}
}
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new MyDesktopDemo();
}
});
}
}
> To assure there were no exceptions being missing
you're original code wouldn't miss any exceptions
still waiting on him to explain why he thinks it would
you're original code wouldn't miss any exceptions
still waiting on him to explain why he thinks it would
ASKER
I jar'd the class and ran it, with no difference (from running in Eclipse)
OK - worth a try
If you were on Unix you could use strace. You might try this for Windows
http://www.intellectualheaven.com/default.asp?BH=projects&H=strace.htm
(or some alternative)
http://www.intellectualheaven.com/default.asp?BH=projects&H=strace.htm
(or some alternative)
Have you tried simply upgrading (or marginally downgrading) the runtime?
ASKER
Currently using JRE 1.6.0_18, dont' want to go any further than _20 because of this:
http://it.slashdot.org/story/10/07/28/2121259/Oracles-Java-Company-Change-Breaks-Eclipse
but I could try _20.
http://it.slashdot.org/story/10/07/28/2121259/Oracles-Java-Company-Change-Breaks-Eclipse
but I could try _20.
most likely its a bug, lots of Desktop bugs on XP
You can try it on the another computer with windows xp (maybe virtual machine)
ASKER
objects:
Looking here:
http://search.oracle.com/search/search?search.timezone=360&search_startnum=21&search_endnum=30&num=10&search_dupid=&exttimeout=false&q=Desktop+winxp+site%3Abugs.sun.com&group=Sun+Defects&sw=t&search_p_main_operator=all&search_p_atname=&search_p_op=equals&search_p_val=&search_p_atname=&search_p_op=equals&search_p_val=
I'm not seeing bugs. Can you point me to them?
Looking here:
http://search.oracle.com/search/search?search.timezone=360&search_startnum=21&search_endnum=30&num=10&search_dupid=&exttimeout=false&q=Desktop+winxp+site%3Abugs.sun.com&group=Sun+Defects&sw=t&search_p_main_operator=all&search_p_atname=&search_p_op=equals&search_p_val=&search_p_atname=&search_p_op=equals&search_p_val=
I'm not seeing bugs. Can you point me to them?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I've tested it with C:\\my.txt file, it opened file my.txt properly without any error. Have you got the right file that you want to open on your computer?
BR,
VanNam