Created
April 29, 2014 08:59
-
-
Save dzwillpower/11394582 to your computer and use it in GitHub Desktop.
将asset 里面的文件转换为file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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