我正在尝试将文件保存到特定目录中。但我得到以下例外
Exception in thread "main" javax.xml.transform.TransformerException: java.io.FileNotFoundException: D:\News\nxis\NewFiles\I0cbf74105a2d11e5b730aca98fc673fd.nxi (The system cannot find the path specified)
at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.getOutputHandler(Unknown Source)
at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transform(Unknown Source)
at org.NXI.CreateNxi.createFiles(CreateNxi.java:49)
at org.NXI.GetInput.main(GetInput.java:24)
Caused by: java.io.FileNotFoundException: D:\News\nxis\NewFiles\I0cbf74105a2d11e5b730aca98fc673fd.nxi (The system cannot find the path specified)
at java.io.FileOutputStream.open(Native Method)
at java.io.FileOutputStream.<init>(Unknown Source)
at java.io.FileOutputStream.<init>(Unknown Source)
... 4 more
---------
java.io.FileNotFoundException: D:\News\nxis\NewFiles\I0cbf74105a2d11e5b730aca98fc673fd.nxi (The system cannot find the path specified)
at java.io.FileOutputStream.open(Native Method)
at java.io.FileOutputStream.<init>(Unknown Source)
at java.io.FileOutputStream.<init>(Unknown Source)
at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.getOutputHandler(Unknown Source)
at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transform(Unknown Source)
at org.NXI.CreateNxi.createFiles(CreateNxi.java:49)
at org.NXI.GetInput.main(GetInput.java:24)
这里实际可用的路径是
String output = "D:\\News\\nxis\\" + replaceGuid + ".nxi";
但我正在尝试在其中添加一个新文件夹。我正在使用以下命令
String output = "D:\\News\\nxis\\New Folder" + replaceGuid + ".nxi";
当我第二步运行我的程序时。它给我一个错误。请让我知道如何解决它。
由于
答案 0 :(得分:3)
这将解决您的问题:
new File(output).mkdir();
mkdir()创建由此抽象路径名命名的目录。
答案 1 :(得分:0)
确保D:\ News \ nxis \目录路径存在,如果不是,则必须创建它。