`
收藏列表
标题 标签 来源
NIO读取文件 按行处理 nio读取文件 按行处理
//NIO读取文件 按行处理
    public static void testMapped() throws IOException {
        long strat = System.currentTimeMillis();
        String filename = "H:\\wokspace\\job\\core\\src\\test\\java\\com\\dajie\\interview\\dao\\SMSDaoTest.java";
        FileInputStream fis = new FileInputStream(filename);
        FileChannel channel = fis.getChannel();
        int length = (int) channel.size();
        MappedByteBuffer byteBuffer =
                channel.map(FileChannel.MapMode.READ_ONLY, 0, length);
        byte [] buffer = new byte[length];
        byteBuffer.get(buffer);
        String str = new String(buffer);
        String[] strArray = str.split("\r\n");
        int i=0;
        while(i != strArray.length){
            System.out.println(strArray[i]);
            i++;
        }

        System.out.println(System.currentTimeMillis() - strat);
    }
Global site tag (gtag.js) - Google Analytics