package com.wo;import java.io.ByteArrayOutputStream;import java.io.IOException;import java.io.InputStream;import org.apache.http.util.EncodingUtils;import android.app.Activity;import android.content.res.Resources;import android.os.Bundle;import android.util.Log;import android.widget.TextView;public class Dfsdf2Activity extends Activity {    TextView tv;    /** Called when the activity is first created. */    @Override    public void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.main);        tv = (TextView) this.findViewById(R.id.tv);        try {            String list[] = this.getAssets().list("book");            for (int i = 0; i < list.length; i++) {                Log.v("tag", list[i]);            }            InputStream is = this.getAssets().open("book/" + list[1]);            byte[] buffer = new byte[is.available()];            is.read(buffer);            String newStr = EncodingUtils.getString(buffer, "gbk");            Log.v("string", newStr);            tv.setText(newStr);        } catch (IOException e) {            // TODO Auto-generated catch block            e.printStackTrace();        }    }    private String readTextFile(InputStream inputStream) {        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();        byte buf[] = new byte[1024];        int len;        try {            while ((len = inputStream.read(buf)) != -1) {                outputStream.write(buf, 0, len);            }            outputStream.close();            inputStream.close();        } catch (IOException e) {        }        return outputStream.toString();    }}

main.xml

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_width="fill_parent"    android:layout_height="fill_parent"    android:orientation="vertical" >    <ScrollView        android:layout_width="fill_parent"        android:layout_height="fill_parent" >        <TextView            android:id="@+id/tv"            android:layout_width="fill_parent"            android:layout_height="wrap_content"            android:text="@string/hello" />    </ScrollView></LinearLayout>



更多相关文章

  1. 代码中设置drawableleft
  2. android 3.0 隐藏 系统标题栏
  3. Android开发中activity切换动画的实现
  4. Android(安卓)学习 笔记_05. 文件下载
  5. Android中直播视频技术探究之—摄像头Camera视频源数据采集解析
  6. 技术博客汇总
  7. android 2.3 wifi (一)
  8. AndRoid Notification的清空和修改
  9. Android中的Chronometer

随机推荐

  1. android 分割线渐变色和几种颜色值定义
  2. Android中设置文本颜色的三种方法
  3. Android 获取界面上的元素
  4. 解析Android消息处理机制 ——Handler/Th
  5. Android操作系统默认图片
  6. eclipse android集成开发环境分享 32位 6
  7. android中的数据存取-方式二:file(文件)
  8. LinearLayout和RelativeLayout 属性对比
  9. Android示例大全教学视频
  10. Android应用的LinearLayout中嵌套Relativ