Results 1 to 6 of 6
- 04-13-2011, 03:00 PM #1
Member
- Join Date
- Apr 2011
- Posts
- 16
- Rep Power
- 0
Error While Running Windows Command Line Instruction
I am running the following code to open a file using the default application in Windows:
The problem is:Java Code:String s1 = jfilechooser.getSelectedFile().getPath(); Runtime rt = Runtime.getRuntime(); Process proc = rt.exec("cmd /c start "+s1);
if the file/directory name contains a space, it does not give the full name at the command line, even though it works PERFECTLY for files/folders whose names do not contain spaces.
eg:
if i select "Hello.txt", it works fine.
but if i select "Bye Dude.txt", Windows gives me an error saying:
"Bye" could not be found.
What should i do to solve this? PLEASE HELP!!!
- 04-13-2011, 03:04 PM #2
Can you add quotes around s1?
To have quotation marks in a String, you have to escape them: "\"I am in quotation marks!\""How to Ask Questions the Smart Way
Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!
- 04-13-2011, 03:34 PM #3
Member
- Join Date
- Apr 2011
- Posts
- 16
- Rep Power
- 0
thank you, Kevin.
got a solution:
Java Code:String fileName = jfilechooser.getSelectedFile().getPath(); String[] commands = {"cmd", "/c", "start", "\"Watever\"",fileName}; Runtime.getRuntime().exec(commands);
- 04-13-2011, 03:36 PM #4
Member
- Join Date
- Apr 2011
- Posts
- 16
- Rep Power
- 0
'watever' is just a random title that i've given to it.
thanks for your help!
- 04-13-2011, 03:37 PM #5
How to Ask Questions the Smart Way
Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!
- 04-13-2011, 04:09 PM #6
Member
- Join Date
- Apr 2011
- Posts
- 7
- Rep Power
- 0
Similar Threads
-
Running Jar file using command line through Java Codes
By NaturalE in forum Advanced JavaReplies: 2Last Post: 02-24-2011, 04:07 AM -
Java command line Windows vs Linux
By shahrukh in forum New To JavaReplies: 2Last Post: 01-16-2011, 05:52 PM -
Command Line Error
By Differintegral in forum New To JavaReplies: 8Last Post: 07-29-2010, 09:49 AM -
javac on the Windows command line--whitespace in path name?
By mslate in forum New To JavaReplies: 2Last Post: 03-31-2010, 12:26 AM -
Compiling/Running Project in Command Line: "Could not find main class" Error
By Yasemin Gokce in forum New To JavaReplies: 1Last Post: 06-30-2009, 02:32 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks