AssetManager assetManager=getAssets();
String strings[] = null;
InputStream inputStream = null;
try {
//seconed
strings=assetManager.list("drawable-hdpi");
inputStream=assetManager.open("a.txt");
// String path = ��music/bg.mp3;
// String path = ��assets/music/bg.mp3;
//String path = ��file:///android_asset/music/bg.mp3;
//String path = ��/music/bg.mp3;
} catch (IOException e) {
e.printStackTrace();
}finally{
assetManager.close();
}
try {
textView.setText(Integer.toString(strings.length)+"file name:"+ strings[0]+" . "
+readTextFile(inputStream));
} catch (IOException e) {
e.printStackTrace();
String strings[] = null;
InputStream inputStream = null;
try {
//seconed
strings=assetManager.list("drawable-hdpi");
inputStream=assetManager.open("a.txt");
// String path = ��music/bg.mp3;
// String path = ��assets/music/bg.mp3;
//String path = ��file:///android_asset/music/bg.mp3;
//String path = ��/music/bg.mp3;
} catch (IOException e) {
e.printStackTrace();
}finally{
assetManager.close();
}
try {
textView.setText(Integer.toString(strings.length)+"file name:"+ strings[0]+" . "
+readTextFile(inputStream));
} catch (IOException e) {
e.printStackTrace();
}
private String readTextFile(InputStream inputStream) throws IOException {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
byte buf[] = new byte [1024];
int len;
try {
while ((len = inputStream.read(buf)) != -1) {
outputStream.write(buf, 0, len);
}
} catch (IOException e) {
Log.v("readText", e.toString());
}finally{
outputStream.close();
inputStream.close();
}
return outputStream.toString();
}