How to launch a windows file from my javaApp?

T

Tomas

Hi,

How do you i.e launch a .txt file in windows from a java application? I've
tried with Runtime.getRuntime().exec("e:\\file\\bla.txt") without sucess.
With that line i only manage to launch .exe files. So how to do to launch
other types of files?

Regards
/Tomas
 
I

Ike

In Windows, if it is a registered file type, simply pass the full path to
the file to:

public static final void openFileAndExecuteAssociatedApplication(String
fullPathAndFileName){
try {
Process p = Runtime.getRuntime().exec("cmd /c start
"+fullPathAndFileName);
p.waitFor();
} catch (Throwable ex) {
ex.printStackTrace();
}
} // Ike
 
T

Tomas

Thanks now it works. But it can not find the file when there are blank spaces
in the directory names in the path like this:

e:\my files\bla.tx

Any idea how to solve that?

Regards Tomas
 
R

Roedy Green

But it can not find the file when there are blank spaces
in the directory names in the path like this:

if you are passing a command line to cmd or 4NT you need to use the
same quoting conventions you would it you were writing bat file.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top