new file,"rawinfo.txt" activity...">
美文网首页
数据存储-读取raw文件中的数据test

数据存储-读取raw文件中的数据test

作者: 糊涂大仙 | 来源:发表于2016-07-08 11:42 被阅读0次

    res->new Directory,"raw"->new file,"rawinfo.txt"

    activity_main.xml

    android:text=" 读取Raw文件夹中的数据"

    android:id="@+id/readrawbtn"

    MainActivity.class

    public classMainActivityextendsAppCompatActivityimplementsView.OnClickListener{

    private static finalStringRAWTAG="ReadRAW";

    privateButtonreadrawbtn;

    @Override

    protected voidonCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_main);

    readrawbtn= (Button)findViewById(R.id.readrawbtn);

    readrawbtn.setOnClickListener(this);

    }

    @Override

    public void onClick(View v) {

    switch(v.getId()) {

    caseR.id.readrawbtn:

    InputStream rawis = getResources().openRawResource(R.raw.rawinfo);

    InputStreamReader rawisr =null;

    try{

    rawisr =newInputStreamReader(rawis,"UTF-8");

    BufferedReader rawbfr =newBufferedReader(rawisr);

    String rawin ="";

    while((rawin = rawbfr.readLine())!=null){

    Log.i(RAWTAG,rawin);

    } }catch(UnsupportedEncodingException e) {

    e.printStackTrace();

    }catch(IOException e) {

    e.printStackTrace();

    }

    break;

    default:

    break;

    }

    }

    }

    运行效果:





    相关文章

      网友评论

          本文标题:数据存储-读取raw文件中的数据test

          本文链接:https://www.haomeiwen.com/subject/phtrjttx.html