title: Javax : Try to find a solution to open an AVI within jar
body: <p>I tried to open an AVI within the executable jar file, the only solution I found is to use FileOutputStream and to make a copy in a temporary file :</p>
  
  <pre><code>InputStream inputStream = getClass().getResourceAsStream(filePathInJar);
  int read = 0;
  byte[] bytes = new byte[1024];
  this.file = new File("c:\\tmpfile.avi");
  OutputStream out = new FileOutputStream(file);
  while ((read = inputStream.read(bytes)) != -1) {
      out.write(bytes, 0, read);
  }
  inputStream.close();
  out.flush();
  out.close();
  </code></pre>
  
  <p>And then I can make :</p>
  
  <pre><code>mediaPlayer = Manager.createRealizedPlayer(new File("c:\\tmpfile.avi").toURI().toURL());
  </code></pre>
  
  <p><b>First question : Do you have any better solution?</b></p>
  
  <p>So with this solution I would delete the temporary file at the end of his use and I tried :</p>
  
  <pre><code>mediaPlayer.stop();
  mediaPlayer.close();
  mediaPlayer.deallocate();
  file.delete()
  </code></pre>
  
  <p>But deletion doesn't work. It seems to be always in use in the player...</p>
  
  <p><b>Second question : How can I stop the use of the temporary file or force to delete?</b></p>
  
  <p>Thanks.</p>