如何逐行读取文件中的内容?

时间:2015-08-04 06:48:36

标签: android

如何逐行读取文件中的内容? 我可以获取内容,但内容在同一行,我如何逐行获取内容?

    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();
        }
    }
};

1 个答案:

答案 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();
}
相关问题