android读取raw下面的文件
16lz
2021-01-24
阅读更多
例如raw文件夹下面的文件是w_city_code.txt,那么读取参考代码如下:
BufferedReader reader=new BufferedReader(new InputStreamReader(getResources().openRawResource(R.raw.w_city_code)));boolean found=false;try {String line;String name;boolean isPreEmpty=true;while((line=reader.readLine())!=null){if(line.length()>10){if(isPreEmpty){name=line.substring(10);if(name.equals(cityName)){// find the city for shenghuifound=true;// search the city names and fill the listcities=searchCitys(line.substring(0, 9),line.substring(10),reader);fillCities(cities);break;}}isPreEmpty=false;}else{isPreEmpty=true;}}} catch (IOException e) {e.printStackTrace();}finally{try {reader.close();} catch (IOException e) {e.printStackTrace();}if(!found){setListAdapter(null);}}
更多相关文章
- Android(安卓)studio编译警告:请使用 -Xlint:deprecation 重新编
- Android培训班(36)
- 【android 文件的基本操作】
- TextView 在xml文件中的解释 android
- Android的Eclipse升级笔记
- android apk编译
- 音视频转码合成
- android 编写命令行测试程序
- android wifi连接