title: Is it possible to create an in-memory File object in Java?
body: <p>One of the optimization projects I'm working on right now makes extensive use of <a href="https://github.com/Baseform/Baseform-Epanet-Java-Library">EPANet</a>. We make repeated calls to two simulation methods in EPANet to understand how water flows through a water distribution network.</p>
  
  <p><a href="https://github.com/Baseform/Baseform-Epanet-Java-Library/blob/master/src/org/addition/epanet/hydraulic/HydraulicSim.java">HydraulicSim</a> is one of the classes we make use of. See the overloaded <code>simulate</code> methods:</p>
  
  <pre><code>public void simulate(File hyd) throws ENException {
      ...
  }
  
  public void simulate(OutputStream out) throws ENException, IOException {
      ...
  }
  
  public void simulate(DataOutput out) throws ENException, IOException {
      ...
  }
  </code></pre>
  
  <p>The other class we use is <a href="https://github.com/Baseform/Baseform-Epanet-Java-Library/blob/master/src/org/addition/epanet/quality/QualitySim.java">QualitySim</a>. Here, we also use the overloaded <code>simulate</code> methods:</p>
  
  <pre><code>public void simulate(File hydFile, File qualFile) throws IOException, ENException {
      ...
  }
  
  void simulate(File hydFile, OutputStream out) throws IOException, ENException {
      ...
  }
  </code></pre>
  
  <p>Here's what we're currently doing:</p>
  
  <ol>
  <li>Create two <code>File</code> objects, <code>hydFile</code> and <code>qualFile</code>.</li>
  <li>Call <code>HydraulicSim.simulate</code> on <code>hydFile</code>.</li>
  <li>Call <code>QualitySim.simulate</code> on <code>hydFile</code> and <code>qualFile</code>.</li>
  <li>Delete the files.</li>
  </ol>
  
  <p>The problem is that we have to do this <em>a lot</em> of times. For a large problem, we can do this hundreds of thousands or even millions of times. You can imagine the slowdown repeatedly creating/writing/deleting these files causes.</p>
  
  <p>So my question is this: Is it possible for me to create these files so that they reside only in memory and never touch the disk? Each file is very small (I'm talking a few hundred bytes), so throwing them into memory won't be a problem; I just need to figure out how. I searched around and didn't really find much, save for <a href="http://docs.oracle.com/javase/7/docs/api/java/nio/MappedByteBuffer.html">MappedByteBuffer</a>, but I'm not sure how, or if it's even possible, to create a <code>File</code> from that class.</p>
  
  <p>Any advice is welcome!</p>