Click here to Skip to main content
15,905,782 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying to read a text file from assets folder which is present in my application folder .
Everything is working perfectly when i click on my button to display the activity with the text file
it experiences delay of 2-3 mins before displaying.

this is my code below kindly help

public class AssetsReader extends ActionBarActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_assets_reader);

TextView txtContent=(TextView)findViewById(R.id.tv1);
TextView txtFileName=(TextView)findViewById(R.id.tv2);
ImageView iv=(ImageView)findViewById(R.id.iv);

AssetManager assetManager=getAssets();

try {

String[] files=assetManager.list("Files");

for (int i = 0; i < files.length; i++) {

txtContent.append("\n Files=>"+i+"Name"+files);
}

} catch (Exception e) {
// TODO: handle exception

e.printStackTrace();
}

InputStream input;

try {

input=assetManager.open("vocab.txt");

int size=input.available();

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

String text=new String(buffer);

txtFileName.setText(text);

} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}

try {

InputStream in=assetManager.open("vocab.jpg");

Drawable d= Drawable.createFromStream(in, null);
iv.setImageDrawable(d);

} catch (Exception e) {
// TODO: handle exception
return;
}
}
Posted
Comments
Richard MacCutchan 2-Apr-15 4:09am    
You need to use your debugger to identify where the delay is occurring.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900