Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / January 2004

Tip: Looking for answers? Try searching our database.

Opening files with spaces in the name

Thread view: 
Steve - 13 Jan 2004 22:00 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:

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 :-)


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.