- package com.example.ch7_1_asset;
- import java.io.IOException;
- import java.io.InputStream;
- import android.os.Bundle;
- import android.app.Activity;
- import android.util.Log;
- import android.view.Menu;
- import android.widget.TextView;
- public class Ch7_1_Asset extends Activity {
- TextView tv1;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.main);
- tv1=(TextView)findViewById(R.id.tv1);
- try {
- InputStream is=getAssets().open("test.txt");
- int size=is.available();
- byte buffer[]=new byte[size];
- is.read(buffer);
- is.close();
- String s=new String(buffer);
- tv1.setText(s);
- } catch (IOException e) {
- // TODO 自動產生的 catch 區塊
- Log.e("Ch7_1_Asset", e.toString());
- }
- }
- }
復制代碼
|