6 Replies Latest reply: Oct 14, 2008 4:26 AM by 807589 RSS

    Error during file open

    807589
      *
      *
      String file = "C:\\Documents and Settings\\mit2kor\\Desktop\\1         1             1             1.txt";
      Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " + file);
      *
      *

      Output:
      I get an 'Unable to open "C:\Documents and Settings\mit2kor\Desktop\1 1 1 1.txt"' error message, when the code snippet is run. Enclosing the variable 'file' within a double quote also does not work.

      Can anybody help?
      Thank you in advance....
        • 1. Re: Error during file open
          807589
          helloamitk wrote:
          1 1 1 1.txt
          Is that really the name of your file? Try renaming.
          • 2. Re: Error during file open
            807589
            Actually, my file name is "1 1 1 1.txt". But the error message says it cannot open "1 1 1 1.txt".
            My sample program is:
            public class test 
            {
              public static void main(String[] args) 
              {
                  try
                  {
                    String file = "C:\\Documents and Settings\\mit2kor\\Desktop\\1         1             1             1.txt";
                    Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " + file);
                  }
                  catch(Exception e)
                  {
                    e.printStackTrace();
                  }
                }
            }
            Can you please help me with the renaming idea? How can I do that?

            Thank you.
            • 3. Re: Error during file open
              807589
              Open Windows Explorer, navigate to where your file is and right click on it. Choose rename. Try something without spaces in it.
              • 4. Re: Error during file open
                807589
                But, i want my code to be able to open a file having any number of white spaces in its name and path.
                • 5. Re: Error during file open
                  807589
                  Try this, on my computer works:
                  String file = "D:\\1  1  1.txt";
                  Runtime.getRuntime().exec(new String[]{"rundll32", "url.dll,FileProtocolHandler", file});
                  By the way, for a single list of consecutive spaces the original code also works. Only if there are two such lists appears I was not able to run the code.
                  Hope this helps

                  Edited by: szgy on Oct 14, 2008 9:18 AM Added the tested file name
                  • 6. Re: Error during file open
                    807589
                    Thank you....It works here too....