TShopping

 找回密碼
 註冊
搜索
TShopping 精選文章 Android 手機開發 查看內容

[Android智慧型手機設計_assets:存取assets目錄內的資源]

2013-7-10 19:53| 發佈者: woff| 查看: 975| 評論: 0|原作者: woff

摘要: package com.example.ch7_1_asset; import java.io.IOException; import java.io.InputStream; import android.os.Bundle; import android.app.Activity; import android.util.Log; import android.view.Menu; impo ...
 
1.jpg

  1. package com.example.ch7_1_asset;

  2. import java.io.IOException;
  3. import java.io.InputStream;
  4. import android.os.Bundle;
  5. import android.app.Activity;
  6. import android.util.Log;
  7. import android.view.Menu;
  8. import android.widget.TextView;

  9. public class Ch7_1_Asset extends Activity {
  10. TextView tv1;
  11. @Override
  12. protected void onCreate(Bundle savedInstanceState) {
  13. super.onCreate(savedInstanceState);
  14. setContentView(R.layout.main);
  15. tv1=(TextView)findViewById(R.id.tv1);
  16. try {
  17. InputStream is=getAssets().open("test.txt");
  18. int size=is.available();
  19. byte buffer[]=new byte[size];
  20. is.read(buffer);
  21. is.close();
  22. String s=new String(buffer);
  23. tv1.setText(s);
  24. } catch (IOException e) {
  25. // TODO 自動產生的 catch 區塊
  26. Log.e("Ch7_1_Asset", e.toString());
  27. }
  28. }
  29. }
復制代碼

最新評論



Archiver|手機版|小黑屋|免責聲明|TShopping

GMT+8, 2024-5-5 18:22 , Processed in 0.098529 second(s), 21 queries .

本論壇言論純屬發表者個人意見,與 TShopping綜合論壇 立場無關 如有意見侵犯了您的權益 請寫信聯絡我們。

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

返回頂部