做网站备案什么意思,企业微网站怎么做,网站建站上市公司,就业网站建设总结Android 系统为每一个新设计的程序提供了/assets文件夹#xff0c;这个文件夹保存的文件能够打包在程序里。/res 和/assets的不同点是#xff0c;android不为/assets下的文件生成ID。假设使用/assets下的文件#xff0c;须要指定文件的路径和文件名称。以下这个样例#xf… Android 系统为每一个新设计的程序提供了/assets文件夹这个文件夹保存的文件能够打包在程序里。/res 和/assets的不同点是android不为/assets下的文件生成ID。假设使用/assets下的文件须要指定文件的路径和文件名称。以下这个样例显示怎样訪问/assets下的内容。 在文件里/assets 中建立/image子文件夹将/res/drawable下的icon.png子文件夹复制到该文件夹中。在/assets子文件夹中建立readme.txt文件文件里输入文本“hello,world!!!”。 布局文件main.xml ?xml version1.0 encodingutf-8 ? LinearLayout xmlns:androidhttp://schemas.android.com/apk/res/android android:orientationvertical android:layout_widthfill_parent android:layout_heightfill_parent TextView android:layout_widthfill_parent android:layout_heightwrap_content android:textstring/hello / EditText android:idid/firstId android:layout_widthfill_parent android:layout_heightwrap_content android:textstring/hello / EditText android:idid/secondId android:layout_widthfill_parent android:layout_heightwrap_content android:textstring/hello / /LinearLayout 程序文件 package com.cn.getassets; import android.app.Activity; import android.os.Bundle; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; import android.app.Activity ; import android.content.res.AssetManager; import android.os.Bundle ; import android.util.Log; import android.widget.EditText; public class GetAssets extends Activity { private EditText firstField; private EditText secondField; Override public void onCreate(Bundle savedInstanceState) { super .onCreate(savedInstanceState); // Log.d(show main.xml,ok ); setContentView(R.layout.main ); Log.d (show main.xml,ok); AssetManager assetManager getAssets(); String[] files null ; try { files assetManager.list(image); } catch (IOException e) { Log.e (tag, e.getMessage()); } firstField (EditText) findViewById(R.id.firstId ); firstField.setText(Integer.toString (files.length)file.File name is files[0]); InputStream inputStream null ; try { inputStream assetManager.open(readme.txt); } catch (IOException e) { Log.e (tag, e.getMessage()); } String s readTextFile(inputStream); secondField (EditText) findViewById(R.id.secondId ); secondField.setText(s); } 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(); } } 程序显示结果使用模拟器。 http://blog.sina.com.cn/s/blog_6cf0d3f30100m2x6.html 转载于:https://www.cnblogs.com/yxwkf/p/3921293.html