결과화면

 

txt파일 경로

 

 

 

// AssetDemo.java

 

 package com.example.hellow;

import java.io.IOException;
import java.io.InputStream;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.widget.LinearLayout;
import android.widget.TextView;

public class AssetDemo extends Activity{
 LinearLayout linear;
 @Override
 protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.asset_demo);

  try{
   InputStream is = getAssets().open("read_asset.txt");
   int size = is.available();
   
   byte[] buffer = new byte[size];
   is.read(buffer);
   is.close();
   
   String text = new String(buffer);
   linear = (LinearLayout)findViewById(R.id.linear);
   TextView tv = new TextView(this);
   tv.setText(text);
   tv.setTextSize(15.0f);
   linear.addView(tv);
  }catch(IOException e){
   Log.e("AssetDemo", "read file from Asset", e);
  }
 }
}


 

 

//  asset_demo.xml

 

 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:id="@+id/linear">


</LinearLayout>

+ Recent posts