首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > Android >

android读取raw底下的文件

2012-07-31 
android读取raw下面的文件例如raw文件夹下面的文件是w_city_code.txt,那么读取参考代码如下:?BufferedRead

android读取raw下面的文件

例如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);}}
?

热点排行