Open a dir and a file with its associated program in win, but in Linux ?
In windows I can open a dir in an explorer window with this java code:
For winnt o 2000
Runtime.getRuntime().exec("cmd /C start c://db /B");
For win9x
Runtime.getRuntime().exec("start c://db");
For opening a file in win I can use this java code:
Runtime.getRuntime().exec("cmd /C start filename /B");
or
Runtime.getRuntime().exec("start filename");
[410 byte] By [
lambu76] at [2007-9-26 10:36:56]

In windows I can open a dir in an explorer window with this java code:
For winnt o 2000
Runtime.getRuntime().exec("cmd /C start c://db /B");
For win9x
Runtime.getRuntime().exec("start c://db");
For opening a file in win I can use this java code:
Runtime.getRuntime().exec("cmd /C start filename /B");
or
Runtime.getRuntime().exec("start filename");
In linux how can I do the same thing ?
Opening dirs and files "the native way" in Linux is not very easy as numerous file managers exist. If you are a KDE user, try this:
Runtime.getRuntime(),exec("kfm file:/<dir>");
GNOME users should address their file manager "Nautilus" an a very similar manner. In order to make your applications portable, you should store the file manager's name in a Properties file.
Opening files with their corresponding applications should work the same way as most X11-based Linux file managers match files by their MIME type with applications siutable for viweing or editing them. Here's an example of opening the PDF file /home/jacek/resources/spacemans_manual.pdf:
Runtime.getRuntime(),exec("kfm file:/home/jacek/resources/spacemans_manual.pdf");
Hope this will work. :-)
Regards,
Jacek.
Yes. Of course, you can use a String variable. However, I am not sure whether you can use the ~ symbol for your home directory in Java.Regards,Jacek.
The phrase "associated program" doesn't exist in Linux per se.
On top of linux, you normally run a shell, and maybe a window manager.
I've never used a shell that pretends to know how to open a file.
Some -not all- window managers have included software (as mentioned above) that acts as a system to keep track of what programs should open which files.
In general the idea of an "associated program" can be rather annoying.
Take .jar files for example. Sometimes I want to run them with "java -jar", sometimes Winzip, and if I really wanted to, with a hex editor.
Then you install some new program and it decides IT should be the program to open jars no matter what you think.
If your're interested, try the "file" command in Linux. It will tell you what type of file a file is. Then you can use that information to deduce which program to use.