Skip to main content
added 89 characters in body
Source Link
Peter Lawrey
  • 535.1k
  • 83
  • 770
  • 1.2k

Try copying 1 KB at a time.

File f = new File(getCacheDir()+"/berlin.mp3");
if (!f.exists()) try {
     byte[] buffer = new byte[1024];
     InputStream is = getAssets().open("berlin.mp3");
     FileOutputStream fos = new FileOutputStream(f);
     int len;
     while((len = is.read(buffer)) > 0) 
        fos.write(buffer, 0, len);
} catch (Exception e) { is.close
     throw new RuntimeException(e); 
} finally {
     fosIOUtils.close(is);
} catch// (Exceptionutility e)to {close throwthe newstream RuntimeExceptionproperly.
     IOUtils.close(efos);  
}

Does Android support symbolic or hand links like UNIX? If it does, this would be faster/more efficient.

Try copying 1 KB at a time.

File f = new File(getCacheDir()+"/berlin.mp3");
if (!f.exists()) try {
     byte[] buffer = new byte[1024];
     InputStream is = getAssets().open("berlin.mp3");
     FileOutputStream fos = new FileOutputStream(f);
     int len;
     while((len = is.read(buffer)) > 0) 
        fos.write(buffer, 0, len);
     is.close();
     fos.close();
} catch (Exception e) { throw new RuntimeException(e); }

Does Android support symbolic or hand links like UNIX? If it does, this would be faster/more efficient.

Try copying 1 KB at a time.

File f = new File(getCacheDir()+"/berlin.mp3");
if (!f.exists()) try {
     byte[] buffer = new byte[1024];
     InputStream is = getAssets().open("berlin.mp3");
     FileOutputStream fos = new FileOutputStream(f);
     int len;
     while((len = is.read(buffer)) > 0) 
        fos.write(buffer, 0, len);
} catch (Exception e) { 
     throw new RuntimeException(e); 
} finally {
     IOUtils.close(is); // utility to close the stream properly.
     IOUtils.close(fos); 
}

Does Android support symbolic or hand links like UNIX? If it does, this would be faster/more efficient.

Source Link
Peter Lawrey
  • 535.1k
  • 83
  • 770
  • 1.2k

Try copying 1 KB at a time.

File f = new File(getCacheDir()+"/berlin.mp3");
if (!f.exists()) try {
     byte[] buffer = new byte[1024];
     InputStream is = getAssets().open("berlin.mp3");
     FileOutputStream fos = new FileOutputStream(f);
     int len;
     while((len = is.read(buffer)) > 0) 
        fos.write(buffer, 0, len);
     is.close();
     fos.close();
} catch (Exception e) { throw new RuntimeException(e); }

Does Android support symbolic or hand links like UNIX? If it does, this would be faster/more efficient.