建设银行开户行地址:如何读取assets文件夹中的txt文件
来源:百度文库 编辑:中财网 时间:2024/04/25 02:50:25
2010-06-20
1.ReadAsset.java文件:
Java代码
2. read_asset.xml文件
Java代码
3.然后在工程里面新建一个assets文件夹,随便放一个index.txt的文件在其中,运行
Ctrl+F11进行测试即可;
分享到: 如何获取屏幕分辨率 | 横、竖屏幕动态切换(layout-land 和layout ...
如何读取assets文件夹中的txt文件
- 博客分类:
- Android(网络相关)
1.ReadAsset.java文件:
Java代码
- package com.example.ReadAsset;
- import android.app.Activity;
- import android.os.Bundle;
- import android.widget.TextView;
- import java.io.IOException;
- import java.io.InputStream;
- public class ReadAsset extends Activity {
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.read_asset);
- try {
- //Return an AssetManager instance for your application's package
- InputStream is = getAssets().open("index.txt");
- int size = is.available();
- // Read the entire asset into a local byte buffer.
- byte[] buffer = new byte[size];
- is.read(buffer);
- is.close();
- // Convert the buffer into a string.
- String text = new String(buffer, "GB2312");
- // Finally stick the string into the text view.
- TextView tv = (TextView) findViewById(R.id.text);
- tv.setText(text);
- } catch (IOException e) {
- // Should never happen!
- throw new RuntimeException(e);
- }
- }
- }
package com.example.ReadAsset;import android.app.Activity;import android.os.Bundle;import android.widget.TextView;import java.io.IOException;import java.io.InputStream;public class ReadAsset extends Activity {@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.read_asset);try {//Return an AssetManager instance for your application's packageInputStream is = getAssets().open("index.txt");int size = is.available();// Read the entire asset into a local byte buffer.byte[] buffer = new byte[size];is.read(buffer);is.close();// Convert the buffer into a string.String text = new String(buffer, "GB2312");// Finally stick the string into the text view.TextView tv = (TextView) findViewById(R.id.text);tv.setText(text);} catch (IOException e) {// Should never happen!throw new RuntimeException(e);}}}
2. read_asset.xml文件
Java代码
- xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_height="fill_parent" android:paddingTop="50dip">
- android:layout_height="wrap_content" android:textStyle="normal" />
3.然后在工程里面新建一个assets文件夹,随便放一个index.txt的文件在其中,运行
Ctrl+F11进行测试即可;
分享到: 如何获取屏幕分辨率 | 横、竖屏幕动态切换(layout-land 和layout ...
在c语言中,如何读取一个txt文件中的信息
请问VB中如何读取txt文件的数据
如何编写在VB中读取TXT文件的语句?
用C读取TXT文件
如何读取网站中的一个文件?
怎么用C语言程序读取txt文件中的浮点型数据
如何在D盘文件夹中建TXT文件
vb读取txt文件的内容
VB读取TXT文件的一个问题
有关vc 读取txt文件的问题
如何把mp3中的文件分割?txt格式
如何把webcompiler中的文件弄出来变成txt
如何编辑FLASH中调用txt文件中的超链接
VB中如何读取 DLL 文件中的资源信息?
困惑!如何读取Ghost映像文件中的内容?
如何读取MP3固件中的 .bin文件
C语言中,如何读取文件中的数据。
如何上传txt文件
如何找到文件夹中的隐藏文件???
如何隐藏E680i中的文件夹或文件
如何获取文件夹中的文件列表
如何读取mmx文件
如何读取wav文件
如何读取max文件