Code for reading from a text file in asset folder to a textview:
public class Readfile extends Activity {
String path;
ArrayList data = new ArrayList();
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
path = getResources().getString(R.string.directory1);
String[] data1 = null;
AssetManager am = getResources().getAssets();
try {
data1 = am.list(path);
} catch (Exception e) {
}
for (String name : data1) {
data.add(name);
}
Readoperation();
}
public void Readoperation() {
// TODO Auto-generated method stub
TextView txt = (TextView) findViewById(R.id.text);
try {
path=getResources().getString(R.string.directory1) +"/"+data.get(2);
InputStream stream = getAssets().open(path);
int size = stream.available();
byte[] buffer = new byte[size];
stream.read(buffer);
stream.close();
txt.setText(Html.fromHtml(new String(buffer).trim()));
}
catch (IOException e) {
}}

Comments
Post a Comment