TShopping

 找回密碼
 註冊
搜索
查看: 1194|回復: 0

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

[複製鏈接]
發表於 2013-6-14 20:47:59 | 顯示全部樓層 |閱讀模式
 
Push to Facebook
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-3-19 10:07 , Processed in 0.060504 second(s), 26 queries .

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

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回復 返回頂部 返回列表