I am trying to open image using java program which file name has more than once spaces. direct windows command is working fine, but when I execute via java program it is not opening.
direct command :
rundll32.exe shell32.dll ShellExec_RunDLL "C:\Logfiles\Client_Logfiles\Attachments\1044\image2 Copy.jpg"
via java:(This is not working)
p_fileName = "C:\Logfiles\Client_Logfiles\Attachments\1044\image2 Copy.jpg"
String cmd = "rundll32.exe shell32.dll ShellExec_RunDLL ";
Runtime.getRuntime().exec(cmd + "\""+p_fileName+"\"");
But if file name has one space, it is fine and opening properly:
Please any ideas on this and appreciate your kind help.
Try with:
p_fileName = "C:\\Logfiles\\Client_Logfiles\\Attachments\\1044\\image2 Copy.jpg"
Or
p_fileName = "C:/Logfiles/Client_Logfiles/Attachments/1044/image2 Copy.jpg"
The problem is you concatenate command. To make it correct use array version of exec and use '/' instead of '\\':
String args[] = {
"rundll32.exe",
"shell32.dll",
"ShellExec_RunDLL",
"C:/Logfiles/Client_Logfiles/Attachments/1044/image2 Copy.jpg"
};
Runtime.getRuntime().exec(args);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.