READ THE FILE AND IMAGE FROM ASSERT FOLDER :
In This code you read the file and Image from Assert folderMain.Class File:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TextView readtext = (TextView) findViewById(R.id.readtext);
ImageView image = (ImageView) findViewById(R.id.image);
AssetManager assetManager = getAssets();
InputStream input;
// To read the text file from assert
try {
input = assetManager.open("helloworld.txt");
int size = input.available();
byte[] buffer = new byte[size];
input.read(buffer);
input.close();
String text = new String(buffer);
readtext.setText(text);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// To get the image from assert
try {
InputStream ims = assetManager.open("android.jpg");
Drawable d = Drawable.createFromStream(ims, null);
image.setImageDrawable(d);
}
catch(IOException ex) {
return;
}
}
}
Main.xml:
<LinearLayoutandroid:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<ImageView
android:id="@+id/image"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/readtext"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</LinearLayout>
Mlife Casino & Hotel - JTG Hub
ReplyDeleteMlife 여수 출장마사지 Casino & Hotel - 전라북도 출장안마 JTG Hub offers a unique place in 군포 출장마사지 JTG hub to experience the 의정부 출장안마 excitement of life in the entertainment 서산 출장마사지 world.