2 Replies Latest reply: Jan 18, 2011 4:16 PM by 832211 RSS

    Troubles copying binary file from zip file inside jar file

    832211
      I have a jar file with an embedded zip file. The zip file contains a directory structure with .png and .jpg files in it. I am attempting to copy the directory structure with the .png and .jpg files to a directory designated by the user. The directory structure is created and the .png and .jpg files are created, but I cannot read them, like it's attempting to do a text copy instead of a binary copy. The file sizes of the copied files seem to be a bit smaller than the originals, so it
      smells like the copy is ending too soon.

      The copy is not throwing an exception.

      Anyone have any hints or suggestions?

      Thanks
      James

      Here is the code I am using:
              try
              {
                  InputStream is  = getClass().getResourceAsStream("resources/palettes_and_textures.zip");
      
                  ZipInputStream zipIn = new ZipInputStream(is);
                  ZipEntry entry = zipIn.getNextEntry();
      
                  while (entry != null)
                  {
                      if (entry.isDirectory())
                      {
                          File newDir  = new File(workDir + File.separator + entry.getName());
                          newDir.mkdirs();
                      }
                      else
                      {
                          String sourcePath = entry.getName();
                          sourcePath = sourcePath.replace("/", File.separator);
      
                          FileOutputStream os = new FileOutputStream(workDir + File.separator + sourcePath);
                          BufferedReader br = new BufferedReader(new InputStreamReader(zipIn));
      
                          int dataByte = br.read();
                          while (dataByte != -1)
                          {
                              os.write(dataByte);
                              dataByte = br.read();
                          }
                          os.close();
                      }
                      entry = zipIn.getNextEntry();
                  }
                  zipIn.close();
              }
              catch(Exception e)
              {
                  theDialog.updateStatus("Could not copy palettes or textures.  Permissions?", true);
                  return;
              }