1

I'm trying to save my file into a perticular directory. but i get the below Exception

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)

Here the path that is available in real is

    String output = "D:\\News\\nxis\\" + replaceGuid + ".nxi";

But i'm trying to add a new folder inside it. I'm using the below command

    String output = "D:\\News\\nxis\\New Folder" + replaceGuid + ".nxi";

When i run my program with the second step. It throws me an error. please let me know how can i fix it.

Thanks

user3872094
  • 3,269
  • 8
  • 33
  • 71
  • http://stackoverflow.com/a/3634906/4088809 – Tahar Bakir Oct 29 '15 at 12:33
  • You should use File.separator (will select needed separator automatically depending on your OS) and be aware of your directory structure before opening the file to prevent such issues. – alexk Oct 29 '15 at 12:34
  • You need to first check if the directory with the path specified exists or not, If not, you need to create it first then only you can create a file in that directory. – Vivek Singh Oct 29 '15 at 12:34
  • `"D:\\News\\nxis\\NewFile\\"` seems to be better. – Joop Eggen Oct 29 '15 at 12:52

2 Answers2

3

this will fix your problem:

new File(output).mkdir();

mkdir() creates the directory named by this abstract pathname.

Dustin
  • 44
  • 4
0

Make sure that D:\News\nxis\ directory path is existing if not you have to create it.

A. Shaheen
  • 105
  • 13