read bigfile

public List<String[]> readBigFile(String filePath)
    {
        List<String[]> object = new ArrayList<String[]>();
        int bufSize = 1024;
        byte[] bs = new byte[bufSize];
        ByteBuffer byteBuf = ByteBuffer.allocate(1024);

        FileChannel channel;
        try
        {
            channel = new RandomAccessFile(filePath, "r").getChannel();

            while (channel.read(byteBuf) != -1)
            {
                int size = byteBuf.position();
                byteBuf.rewind();
                byteBuf.get(bs);

                // 把文件当字符串处理
                String str = new String(bs, 0, size);

                String[] strList = str.split(",");
                // 可以写一个解析方法decode() or parser(),把数组的值对应放到对象里。

                byteBuf.clear();
                object.add(strList);
            }
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
        return object;

    }

你可能感兴趣的:(exception,object,String,byte)