如何逐行读取文件中的内容? 我可以获取内容,但内容在同一行,我如何逐行获取内容?
FileInputStream fileIn =null;
BufferedInputStream bufFileIn=null;
try{
fileIn = openFileInput("AlbumEdit.txt");
bufFileIn = new BufferedInputStream(fileIn);
byte[] bufBytes = new byte[20];
medtplay.setText("");
do{
int c = bufFileIn.read(bufBytes);
if(c==-1)break;
else medtplay.append(new String(bufBytes),0,c);
} while (true);
bufFileIn.close();
}catch(Exception e){
e.printStackTrace();
}
}
};
答案 0 :(得分:2)
试试此代码
BufferedReader reader;
try{
final InputStream file = getAssets().open("text.txt");
reader = new BufferedReader(new InputStreamReader(file));
String line = reader.readLine();
while(line != null){
line = reader.readLine();
}
} catch(IOException ioe){
ioe.printStackTrace();
}