码迷,mamicode.com
首页 > 其他好文 > 详细

读取assets目录

时间:2015-06-28 14:07:25      阅读:102      评论:0      收藏:0      [点我收藏+]

标签:

public class MainActivity extends Activity {
    
    private static final String TAG = "read";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        findViewById(R.id.btn_read_txt).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                try {
                    InputStream is = getResources().getAssets().open("info.txt");
                    InputStreamReader isr = new InputStreamReader(is,"UTF-8");//显示规定编码是好习惯,免得乱码.
                    BufferedReader br = new BufferedReader(isr);
                    String lineData = "";
                    while((lineData = br.readLine()) != null){
                        Log.i(TAG, lineData);
                    }
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        });
    }
}

 

读取assets目录

标签:

原文地址:http://www.cnblogs.com/cocl/p/4605437.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!