做个记录,读取assets文件夹txt格式文件内容,每行作为一个对象
public List<String> readFileOnLine(String name){//输入文件名字
List<String> list = new ArrayList<String>();
try {
// FileInputStream fis = openFileInput(filePath);
// 打开文件输入流
// InputStream is = getAssets().open(name);
InputStream is = getAssets().open(name);
StringBuffer sBuffer = new StringBuffer();
DataInputStream dataIO = new DataInputStream(is);//读取文件数据流
String strLine = null;
while ((strLine = dataIO.readLine()) != null) {//通过readline按行读取
// sBuffer.append(strLine + "\n");//strLine就是一行的内容
list.add(strLine);
}
dataIO.close();
is.close();
}catch (Exception e){
e.printStackTrace();
Log.e("bajiu",name+"读取出错");
}
return list;
}