Exemplo n.º 1
0
  private boolean unpackFile(ZipFile zip, byte[] buf, ZipEntry fileEntry, String name)
      throws IOException, FileNotFoundException {
    if (fileEntry == null) fileEntry = zip.getEntry(name);
    if (fileEntry == null)
      throw new FileNotFoundException("Can't find " + name + " in " + zip.getName());

    File outFile = new File(sGREDir, name);
    if (outFile.lastModified() == fileEntry.getTime() && outFile.length() == fileEntry.getSize())
      return false;

    File dir = outFile.getParentFile();
    if (!dir.exists()) dir.mkdirs();

    InputStream fileStream;
    fileStream = zip.getInputStream(fileEntry);

    OutputStream outStream = new FileOutputStream(outFile);

    while (fileStream.available() > 0) {
      int read = fileStream.read(buf, 0, buf.length);
      outStream.write(buf, 0, read);
    }

    fileStream.close();
    outStream.close();
    outFile.setLastModified(fileEntry.getTime());
    return true;
  }
Exemplo n.º 2
0
  public static Bitmap getBitmapByAssets(Context context, String path) {
    Bitmap bitmap = null;
    InputStream in = null;
    try {
      in = context.getResources().getAssets().open(path);
      bitmap = BitmapFactory.decodeStream(in);
    } catch (Exception e) {

    } finally {
      try {
        in.close();
      } catch (Exception ex) {

      }
    }
    return bitmap;
  }