String filepath = E:\TestCode\My Demo File\abc.xml
我想用这个文件路径创建文件,这个文件路径有空格。带空格的文件路径
FileInputStream file = new FileInputStream(new File(filePath));
DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = builderFactory.newDocumentBuilder();
Document xmlDocument = builder.parse(file);
它抛出FileNotFoundException
。
请参阅http://docs.oracle.com/javase/tutorial/java/data/characters.html。您需要在字符串中使用“\\”而不是“\”。 – DavidPostill
你知道这四行中的哪一行会抛出异常吗? –
'String filepath = E:\ TestCode \ My Demo File \ abc.xml' will not compile .. –