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 .. –