title: creating a directory in java
body: <p>I'm trying to create a directory and copy files to it. The code I've implemented and its output is below. The problem seems self explanatory, but I'll make it explicit for those who can't tell.</p>
  
  <h2>Problem</h2>
  
  <hr>
  
  <p>No matter what I do, I can't seem to create the destination file required to copy the file.</p>
  
  <h2>Code</h2>
  
  <hr>
  
  <p><code>get</code> is the file to be copied, and <code>dest</code> is the directory to which it will be copied. Line numbers and "<code>ERR&gt;</code>" were added for clarity. I've commented out other methods of file creation which I've tried, but they all failed.</p>
  
  <pre><code>115:  private void copyTo(File get, File dest)
  116:  {
  117:    try
  118:    {
  119:      dest = new File((dest.getPath().endsWith(File.separator) ? dest.getPath() : dest.getPath() + File.separator) + get.getName());
  120:      
  121:      java.io.FileInputStream fis = new java.io.FileInputStream(get);
  122:      if (dest.exists())
  123:        while(!dest.delete());
  124:      dest.mkdir();
  125://      dest.createNewFile();
  126://      java.io.FileWriter w = new java.io.FileWriter(dest);
  127://      w.write("");
  128:      System.out.println("Writing \"" + get + "\" to \"" + dest + "\"");
  129:ERR&gt;  java.io.FileOutputStream fos = new java.io.FileOutputStream(dest);
  130:      int b;
  131:      do
  132:      {
  133:        b = fis.read();
  134:        fos.write(b);
  135:      }while (b != -1);
  136:    }
  137:    catch (FileNotFoundException ex)
  138:    {
  139://      System.err.println("404: \"" + get + "\"");
  140:      ex.printStackTrace();
  141:    }
  142:    catch (java.io.IOException ex)
  143:    {
  144://      System.err.println("IO exception on \"" + get + "\"");
  145:      ex.printStackTrace();
  146:    }
  147:  }
  </code></pre>
  
  <h2>Output</h2>
  
  <hr>
  
  <pre><code>Writing "J:\warehouse.txt" to "J:\backup\warehouse.txt"
  java.io.FileNotFoundException: J:\backup\warehouse.txt (The system cannot find the path specified)
          at java.io.FileOutputStream.open(Native Method)
          at java.io.FileOutputStream.&lt;init&gt;(FileOutputStream.java:179)
          at java.io.FileOutputStream.&lt;init&gt;(FileOutputStream.java:131)
          at copy.TUI.copyTo(TUI.java:129)
          at copy.TUI.copy(TUI.java:110)
          at copy.TUI.run(TUI.java:102)
          at copy.Main.main(Main.java:37)
  </code></pre>