Skip to content

Instantly share code, notes, and snippets.

@dzwillpower
Created April 29, 2014 08:59
Show Gist options
  • Save dzwillpower/11394582 to your computer and use it in GitHub Desktop.
Save dzwillpower/11394582 to your computer and use it in GitHub Desktop.
将asset 里面的文件转换为file
AssetManager am = getAssets();
InputStream inputStream = am.open(file:///android_asset/myfoldername/myfilename);
File file = createFileFromInputStream(inputStream);
private File createFileFromInputStream(InputStream inputStream) {
try{
File f = new File(my_file_name);
OutputStream outputStream = new FileOutputStream(f);
byte buffer[] = new byte[1024];
int length = 0;
while((length=inputStream.read(buffer)) > 0) {
outputStream.write(buffer,0,length);
}
outputStream.close();
inputStream.close();
return f;
}catch (IOException e) {
//Logging exception
}
return null;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment