I'm trying to write some java code that will open a file in its
default viewer in windows. I have this right now:
Process proc = Runtime.getRuntime().exec("RunDLL32.EXE
SHELL32.DLL,OpenAs_RunDLL " + filename);
This works perfectly except if the pathname of the file contains more
than one space in a row which is perfectly legal for a windows
pathname. One space in a file pathname works fine. I tried putting
quotes around the path name and when I do this windows seems to
convert all the multiple spaces to a single space so it can't find the
file. Any suggestions would be greatly appreciated.
Thanks in advance,
Steve
Tanktarta - 13 Jan 2004 22:53 GMT
> I'm trying to write some java code that will open a file in its
> default viewer in windows. I have this right now:
[quoted text clipped - 11 lines]
> Thanks in advance,
> Steve
Try call Runtime.exec() using an array of arguments instead. I.e.
String[] args = { "RunDLL32.EXE", "SHELL32.DLL", "OpenAs_RunDLL", filename };
Process proc = Runtime.getRuntime().exec(args);
Brett
Steve - 14 Jan 2004 04:06 GMT
> > I'm trying to write some java code that will open a file in its
> > default viewer in windows. I have this right now:
[quoted text clipped - 18 lines]
>
> Brett
That works perfectly. Thanks so much. A simple solution but I didn't
think of it. Strange that using the array makes a difference. Thanks
again.
Steve
Steve W. Jackson - 14 Jan 2004 17:26 GMT
>:Tanktarta <tanktarta_magicthize@hotmail.com> wrote in message
>:news:<pan.2004.01.13.22.54.01.723937@hotmail.com>...
[quoted text clipped - 29 lines]
>:
>:Steve
Not strange at all when you dig closely enough into the API. There's a
hidden clue in there someplace that says that the String argument is
tokenized...and it's done by spaces. :-)
The odd thing to me is why the above works so well, when in my case I
still had to actually include quotes around the Windows filename entry
in the array to make it work. Perhaps I didn't "hold my mouth right",
as the saying goes.
= Steve =

Signature
Steve W. Jackson
Montgomery, Alabama
Manolis Christodoulou - 14 Jan 2004 13:53 GMT
>>I'm trying to write some java code that will open a file in its
>>default viewer in windows. I have this right now:
[quoted text clipped - 16 lines]
> String[] args = { "RunDLL32.EXE", "SHELL32.DLL", "OpenAs_RunDLL", filename };
> Process proc = Runtime.getRuntime().exec(args);
And what about if I want to open a file (not run a windows program or
.bat file) and I have to get the full path with
ClassLoader.getSystemResource("my file").getPath();
Then I take a %20 for every space. If then I try to create that file I
take a path and a file on my hard disk like this :
c:\documents%20and%20settings\mchris\my%20documents\my%20webs\personal%20web%20page\my%20file.html
Is this anything more stupid than the name "documents and settings" for
the folder to hold user accounts?
Andrew Thompson - 14 Jan 2004 04:39 GMT
| Process proc = Runtime.getRuntime().exec("RunDLL32.EXE
| SHELL32.DLL,OpenAs_RunDLL " + filename);
[quoted text clipped - 5 lines]
| convert all the multiple spaces to a single space so it can't find the
| file.
Oh, clever windows
|..Any suggestions would be greatly appreciated.
(you did say _any_) Try replacing your ' 's
with '%20's or whatever the same as an URI..
HTH
--
Andrew Thompson
* http://www.PhySci.org/ PhySci software suite
* http://www.1point1C.org/ 1.1C - Superluminal!
* http://www.AThompson.info/andrew/ personal site
Andrew Thompson - 14 Jan 2004 04:41 GMT
| I'm trying to write some java code that will open a file in its
| default viewer in windows. I have this right now:
And.. What did any of that
have to do with GUI's?
c.l.j.programmer might have
been a better choice of forum.
[ I don't think mention of 'windows'
makes it a GUI matter.. ;-) ]
Steve - 14 Jan 2004 22:54 GMT
> | I'm trying to write some java code that will open a file in its
> | default viewer in windows. I have this right now:
[quoted text clipped - 7 lines]
> [ I don't think mention of 'windows'
> makes it a GUI matter.. ;-) ]
The GUI part comes in because I was clicking on a list of files
displayed in a JFrame. Mentioning windows didn't make it a GUI
question :-)