0
votes
String filepath = "C:/UIDriverProject/UIDriverPro/Test Folder/TESTDATA/TEST.dat";
DocumentBuilderFactory docFactory = 
DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
Document doc = docBuilder.parse(filepath);

String filepath = "C:/UIDriverProject/UIDriverPro/Test Folder/TESTDATA/TEST.dat";

I'm using the FILE PATH with space - "Test Folder". If i give folder without space its working perfectly but with space its saying error message like below error message.

javax.xml.transform.TransformerException: java.io.FileNotFoundException: C:\UIDriverProject\UIDriverPro\Test%20Folder\TESTDATA\TEST.dat (The system cannot find the path specified) at org.apache.xalan.transformer.TransformerIdentityImpl.createResultContentHandler(TransformerIdentityImpl.java:297) at org.apache.xalan.transformer.TransformerIdentityImpl.transform(TransformerIdentityImpl.java:330) at org.apache.xalan.transformer.TransformerIdentityImpl$transform$0.call(Unknown Source) at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:133) at helper.click_helper.updateXML(click_helper.groovy:148) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:93) at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:325) at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1215) at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1024) at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:812) at groovy.lang.DelegatingMetaClass.invokeMethod(DelegatingMetaClass.java:144) at helper.click_helper.invokeMethod(click_helper.groovy) at com.kms.katalon.core.main.CustomKeywordDelegatingMetaClass.invokeStaticMethod(CustomKeywordDelegatingMetaClass.java:46) at org.codehaus.groovy.runtime.callsite.StaticMetaClassSite.call(StaticMetaClassSite.java:53) at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:117) at Script1526547459389.run(Script1526547459389.groovy:30) at com.kms.katalon.core.main.ScriptEngine.run(ScriptEngine.java:183) at com.kms.katalon.core.main.ScriptEngine.runScriptAsRawText(ScriptEngine.java:108) at com.kms.katalon.core.main.TestCaseExecutor.runScript(TestCaseExecutor.java:295) at com.kms.katalon.core.main.TestCaseExecutor.doExecute(TestCaseExecutor.java:286) at com.kms.katalon.core.main.TestCaseExecutor.processExecutionPhase(TestCaseExecutor.java:265) at com.kms.katalon.core.main.TestCaseExecutor.accessMainPhase(TestCaseExecutor.java:257) at com.kms.katalon.core.main.TestCaseExecutor.execute(TestCaseExecutor.java:201) at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:86) at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:77) at com.kms.katalon.core.main.TestCaseMain$runTestCase$0.call(Unknown Source) at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:149) at TempTestCase1526623462047.run(TempTestCase1526623462047.groovy:20) at groovy.lang.GroovyShell.runScriptOrMainOrTestOrRunnable(GroovyShell.java:263) at groovy.lang.GroovyShell.run(GroovyShell.java:518) at groovy.lang.GroovyShell.run(GroovyShell.java:507) at groovy.ui.GroovyMain.processOnce(GroovyMain.java:653) at groovy.ui.GroovyMain.run(GroovyMain.java:384) at groovy.ui.GroovyMain.process(GroovyMain.java:370) at groovy.ui.GroovyMain.processArgs(GroovyMain.java:129) at groovy.ui.GroovyMain.main(GroovyMain.java:109) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.codehaus.groovy.tools.GroovyStarter.rootLoader(GroovyStarter.java:109) at org.codehaus.groovy.tools.GroovyStarter.main(GroovyStarter.java:131) Caused by: java.io.FileNotFoundException: C:\UIDriverProject\UIDriverPro\Test%20Folder\TESTDATA\TEST.dat (The system cannot find the path specified) at java.io.FileOutputStream.open0(Native Method) at java.io.FileOutputStream.open(FileOutputStream.java:270) at java.io.FileOutputStream.(FileOutputStream.java:213) at java.io.FileOutputStream.(FileOutputStream.java:101) at org.apache.xalan.transformer.TransformerIdentityImpl.createResultContentHandler(TransformerIdentityImpl.java:287) ... 51 more

2
Your problem is that the document builder coverts spaces to %20 to be URL safe, yet it is not opening a URL, just a file. Does document builder supports URL type as input? If yes, you could try file://C:/... ...Oleg Sklyar
please post the body of your DocumentBuilder.parse methodkejn

2 Answers

2
votes

You should try this:

    String filepath = "C:/UIDriverProject/UIDriverPro/Test Folder/TESTDATA/TEST.dat";
    URI file = new File(filepath).toURI();
    DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
    DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
    Document doc = docBuilder.parse(file.toURL().toString());

Converting to URI object makes sure that the whitespaces are taken care for URI file = new File(filepath).toURI();

-1
votes

Please try modifying the code to the following, and let me know if it fixes it.

    File filepath = new File("C:/UIDriverProject/UIDriverPro/Test Folder/TESTDATA/TEST.dat");
    DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
    DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
    Document doc = docBuilder.parse(filepath);