2013年7月11日 星期四

Read a asset file into a String

private String assetFile2Str(String path) throws IOException {
InputStream is = getAssets().open(path);
int size = is.available();

byte[] buffer = new byte[size];
is.read(buffer);
is.close();

String str = new String(buffer);
return str;
}

where path should be a relative path to the base URL, for example, if there is a target file located at:

file:///android_asset/www/test.html

then you should put "www/test.html" as path.

Reference links
http://stackoverflow.com/questions/11157876/read-html-file-from-assets

沒有留言:

張貼留言