前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >android 获取文件某一行

android 获取文件某一行

原创
作者头像
八神太一
修改2021-04-06 11:15:33
9990
修改2021-04-06 11:15:33
举报
文章被收录于专栏:androud

android 获取文件某一行

代码语言:javascript
复制
System.out.println( readLineFile(filePath.getPath(),15)); 
	} 
	public static String readLineFile(String filePath,int readLine) {
        String line;
        StringBuilder sb = new StringBuilder();


        int lines=0;
        try {
            //fileReader = new FileReader(filePath);
            InputStreamReader inputStreamReader=new InputStreamReader(
				new FileInputStream(filePath),"GBK");
            BufferedReader br = new BufferedReader(inputStreamReader);
            while ((line = br.readLine()) != null) {
                lines++;
				//byte[] bytes= line.getBytes("GBK");
                if (lines>=readLine){
					sb.append(line);
                    return sb.toString();
                }else {
                    //sb.append(line).append('\n');
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        //	System.out.println( sb.toString());


		return  sb.toString();
	
	
    }

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档