【发布时间】:2012-10-26 11:58:26
【问题描述】:
我已经使用 DOMparser 解析了一批 XML Schema 文件。然后我添加了几个注释,这对于我正在创建的应用程序是必不可少的。然后我想将这些新的“预处理”文件写入一个新位置,我得到一个 FileNotFound 异常(访问被拒绝)。
这是我正在编写文件的代码的 sn-p:
Transformer tFormer = TransformerFactory.newInstance().newTransformer();
// Set output file to xml
tFormer.setOutputProperty(OutputKeys.METHOD, "xml");
// Write the document back to the file
Source source = new DOMSource(document);
File preprFile = new File(newPath(xmlFile));
// The newPath function is a series of String operations that result in a new
relative path
try {
// Create file if it doesn't already exist;
preprFile.mkdirs();
preprFile.createNewFile();
} catch (Exception e) {
e.printStackTrace();
}
Result result = new StreamResult(preprFile);
tFormer.transform(source, result);
我得到的错误如下:
java.io.FileNotFoundException: absolutePathHere (Access is denied)
上面sn-p中哪个指向这一行:
tFormer.transform(source, result);
我使用的是 Windows 机器(在某处可能会导致此错误),并且我已经尝试关闭 UAC,但没有成功。
我在想也许 createNewFile() 方法在文件创建后不会释放文件,但无法找到更多相关信息。
希望 StackOverflow 能再次帮助我。
【问题讨论】:
-
显示的是哪个路径?来源还是结果?是否正在创建文件?
-
你在本地系统或其他服务器上试过这个吗?请给出您在 File 对象中使用的 xml 路径。
-
目录已创建,并且文件似乎也被创建为目录,我觉得这特别奇怪。我在本地系统上运行它,我使用的路径是
target\zips\kbo_services_schemas\be\fgov\economie\kbo\R16\WSReportKBO\preprocessed\wsreportkbo_messages.xsd好吧,至少这是 getPath 的输出。输入相同,但带有正斜杠
标签: java xml file xsd filenotfoundexception