我怎样才能确定在java文件的每一行的字节数? [英] How can I determine the number of bytes of each line of a file in java?

查看:171
本文介绍了我怎样才能确定在java文件的每一行的字节数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个非常大的文本文件。我想确定每一行的字节数,并保存在另一个文件中。

下面的代码提取

  byte [] chunks = null; 
BufferedReader in =
BufferedReader(new InputStreamReader(new FileInputStream(path +/+ filePath),UTF-8));
String eachLine =; ((eachLine = in.readLine())!= null)

{
chunks = eachLine.getBytes(UTF-8);
System.out.println(chunks.length);
}


I have a very big text file. I want to determine the number of bytes of each line and save it in another file.

解决方案

The following code extracts

   byte[] chunks  = null;
        BufferedReader  in = 
        new BufferedReader (new InputStreamReader(new FileInputStream(path +"/"+filePath),"UTF-8"));
        String eachLine  = "";  
        while( (eachLine = in.readLine()) != null) 
        {
            chunks = eachLine.getBytes("UTF-8");
            System.out.println(chunks.length);
        } 

这篇关于我怎样才能确定在java文件的每一行的字节数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆