首先在res目录下新建一个raw文件夹,然后在raw文件夹中新建一个text.txt文件用来读取
读取文件代码如下:
findViewById(R.id.btn).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { InputStream is = getResources().openRawResource(R.raw.text); try { InputStreamReader isr = new InputStreamReader(is, "UTF-8"); BufferedReader bfr=new BufferedReader(isr); String inString=""; while((inString=bfr.readLine())==null){ Log.i("RawDate",inString); } } catch (UnsupportedEncodingException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } }); }
时间: 2024-10-05 10:52:04