views:

109

answers:

2

I use the following code to display a gif image in Java by calling a runtime command, it opens the WindowsPhotoGallery, but doesn't display my image, instead it shows a bunch of other pictures on my PC, my question is : how to pass the gif image file name to it properly, so it will open with my image.

Now I'm passing it like this : C:\Program Files\Windows Photo Gallery\WindowsPhotoGallery "C:/abc.gif"

Which is incorrect, what's the right way to do it ?

String Command,Program,File_Path="C:/abc.gif";
Process process=null;

Program="C:\\Program Files\\Windows Photo Gallery\\WindowsPhotoGallery ";          
Command=Program+"\""+File_Path+"\"";

try { process=Runtime.getRuntime().exec(Command); }
catch (Exception e) { e.printStackTrace(); }
A: 

The problem is in the command line string.

for example : c:\document and settting\pic.gif = "\"c:\document and setting\pic.gif\""

ariso
I don't quite get it. My actual command look this this :C:/Program Files/Windows Photo Gallery/WindowsPhotoGallery C:/Dir_Stock_Data/ACC.gifI tried to put quotes around it different ways, the results are still the same. What did I do wrong ?
Frank
+1  A: 

You can use Runtime.exec(String[] cmdArray) to pass a command and its arguments.

Valentin Rocher