Android 逐行读取本地文件

来源:互联网 发布:电脑壁纸软件哪个好 编辑:程序博客网 时间:2024/06/05 17:39

读取本地文件做个记录
本地.txt文件内容如下
100
cctv1,url
cctv2,url
cctv3,url
cctv4,url
需要逐行读取出来

        /**读取文件 * @param strFilePath */public List<String> readFile(String strFilePath){    List<String> txtList = new ArrayList<>();    File file = new File(strFilePath);    if (file.isDirectory()){        Log.d(TAG, "The File doesn't not exist.");    }else{        try{            InputStream instream = new FileInputStream(file);            if (instream != null){                InputStreamReader inputreader = new InputStreamReader(instream);                BufferedReader buffreader = new BufferedReader(inputreader);                String line;                //逐行读取                while (( line = buffreader.readLine()) != null){                    txtList.add(line);                }                instream.close();            }        }catch(Exception e){            e.printStackTrace();        }    }    return txtList;}
原创粉丝点击