把 .txt文件 放在 assets文件夹中



public class MainActivity extends Activity {

public static final String ENCODING = "GBK";
private TextView teView;



@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
teView = (TextView) findViewById(R.id.button1);
editText2 = (EditText) findViewById(R.id.editText2);
intent_two = (Button) findViewById(R.id.intent_two);

teView.setText(getFromAssets("xieyi.txt"));

                 public String getFromAssets(String fileName) {
String result = "";
try {
InputStream in = getResources().getAssets().open(fileName);
// 获取文件的字节数
int lenght = in.available();
// 创建byte数组
byte[] buffer = new byte[lenght];
// 将文件中的数据读到byte数组中
in.read(buffer);
result = EncodingUtils.getString(buffer, ENCODING);
} catch (Exception e) {
e.printStackTrace();
}
return result;
}

<?xml version="1.0" encoding="UTF-8"?>
    android:id="@+id/login_scroll"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:fillViewport="true"
    android:orientation="vertical" >




            android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_marginTop="100dp" >


                    android:layout_width="wrap_content"
            android:layout_height="wrap_content" >


                            android:id="@+id/button1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" />
       

   



更多相关文章

  1. 【Android】 Android中适配器简介
  2. android日期控件显示
  3. android java 检测文件夹(目录)是否存在,不存在则创建
  4. Android(安卓)zip文件压缩解压缩
  5. android截取屏幕图片
  6. make: *** [out/host/linux-x86/obj/EXECUTABLES/emulator_inter
  7. Android常用功能代码块
  8. 箭头函数的基础使用
  9. NPM 和webpack 的基础使用

随机推荐

  1. Android studio报错:找不到匹配的任何版本
  2. Android 利用Java实现压缩与解压缩(zip、g
  3. android分享,如何移除掉信息这项
  4. CooradicatoarLayout 介绍
  5. 判断应用是安装还是卸载了
  6. android 3.0以上对usb设备的访问USB
  7. 导入android-support-v7-appcompat出现问
  8. Android error:Lint found fatal errors
  9. 去除android锁屏
  10. 手机壁纸设置相关