因为开发需要,经常要从工程的assets文件夹里面读取文件,现在贴一个方法以作记录:
private void getFromAssets(String fileName, ArrayList<String> nameSet){
try {
InputStreamReader inputReader = new InputStreamReader( getResources().getAssets().open(fileName) );
BufferedReader bufReader = new BufferedReader(inputReader);
String line="";
while((line = bufReader.readLine()) != null){
nameSet.add(line);
}
Log.i(TAG,"into getFromAssets nameList size is: " + nameSet.size() + " nameSet = " + nameSet);
bufReader.close();
} catch (IOException e) {
e.printStackTrace();
}
}
时间: 2024-10-12 13:25:37