title: ZipFile constructor - correct way of using its mode and charset arguments
body: <p><a href="https://docs.oracle.com/javase/8/docs/api/java/util/zip/ZipFile.html#ZipFile-java.io.File-int-java.nio.charset.Charset-" rel="nofollow noreferrer">Here</a> is <code>ZipFile</code> constructor</p>
  
  <pre><code> ZipFile(File file, int mode, Charset charset) throws IOException
  </code></pre>
  
  <p>How are <code>mode</code> and <code>charset</code> arguments used exactly? What are they for?</p>
  
  <p>1) mode = <code>ZipFile.OPEN_DELETE</code></p>
  
  <p>When the file is deleted?  </p>
  
  <p>Besides this is not deleting separate files within zip-archive - why don't I just delete my zip file using <code>File.delete()</code> or <code>File.deleteOnExit()</code>? </p>
  
  <blockquote>
    <p>The file will be deleted some time between the moment that it is
    opened and the moment that it is closed, but its contents will remain
    accessible via the ZipFile object until either the close method is
    invoked or the virtual machine exits.</p>
  </blockquote>
  
  <p>So I delete a file like this:</p>
  
  <pre><code>try {
  
      ZipFile zf = new ZipFile(new File("myZipFile.zip"), ZipFile.OPEN_DELETE);           
  
      // file name and comment are not read in this binary stream, do they?
      zf.getInputStream(zf.getEntry("dirInZip/fileInsideZip.txt"));
      // some operations
  
      zf.close(); // closes InputStream and deletes myZipFile.zip ?
  
  } catch (IOException e) {
      // handling
  }
  </code></pre>
  
  <p>2) Charset argument:</p>
  
  <blockquote>
    <p>The charset to be used to decode the ZIP entry name and comment
    (ignored if the language encoding bit of the ZIP entry's general
    purpose bit flag is set).</p>
  </blockquote>
  
  <p>I don't understand it at all. </p>
  
  <p>Before running some zip utility, file names (to be zipped) might be in non-UTF encoding (theoretically on a very old Windows it might be Windows-1252 codepage, etc), besides when I run WinZip or something I can copy-paste non-UTF text as a comment - but aren't there some standard how filenames and comment shall be stored within ZIP (I mean WinZip or such would force/change encoding to UTF-8 before zipping) ?</p>
  
  <p>2.1) In which case I might expect non-UTF filenames and comment within Zip?</p>
  
  <p>2.2) Using myZipFile.getEntry("dirInZip/fileInsideZip.txt") I use java String which is UTF16 inherently, so why should I ever care about encoding? I just write whatever into java String, right?</p>