java 逐行读取文件(读取文件每一行、按行读取文件)附带示例代码

这篇具有很好参考价值的文章主要介绍了java 逐行读取文件(读取文件每一行、按行读取文件)附带示例代码。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

BufferedReader

最快的读取每一行

	@Test
    public void bufferReaderTest() {
        try (BufferedReader bufferedReader = new BufferedReader(new FileReader("D:\\aa.txt"))) {
            String line;
            while ((line = bufferedReader.readLine())  != null) {
                // 处理每一行数据 .....
            }
        } catch (Exception e) {
            log.error(e.getMessage(), e);
        }
    }

Scanner

相比较Scanner慢一点

 	@Test
    public void scannerTest() {
        try (Scanner scanner = new Scanner(new File("D:\\aa.txt"))) {
            while (scanner.hasNextLine()) {
                // 处理每一行数据 .....
                String line = scanner.nextLine();

            }
        } catch (Exception e) {
            log.error(e.getMessage(), e);
        }
    }

RandomAccessFile

行数达到一定规模,使用此方法读取会非常慢

	@Test
    public void randomAccessFileTest() {
        try (RandomAccessFile accessFile = new RandomAccessFile("D:\\aa.txt", "r")) {
            String line;
            while ((line = accessFile.readLine()) != null) {
                // 处理每一行数据 .....

            }
        } catch (Exception e) {
            log.error(e.getMessage(), e);
        }
    }

Files

一次把所有数据都读到内存中,当文件非常大时,会消耗掉内存资源导致程序崩掉,文件规模小推荐使用

	@Test
    public void filesTest() {
        try {
            List<String> lines = Files.readAllLines(Paths.get("D:\\aa.txt"));
            lines.forEach(line -> {
                // 处理每一行数据 .....

            });
        } catch (Exception e) {
            log.error(e.getMessage(), e);
        }
    }

示例代码

统计每一行日志ip出现的次数文章来源地址https://www.toymoban.com/news/detail-514503.html

package io;

import lombok.extern.slf4j.Slf4j;
import org.junit.Test;  

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.RandomAccessFile;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;

/**
 * @Author: Lisy
 * @Date: 2023/04/17/9:51
 * @Description: 读取文件中每一行的数据
 */
@Slf4j
public class ReadLineTest {

    private final String FILE_NAME = "D:\\aa.txt";
    private Map<String, Integer> StringMap = new HashMap<>();

     @Test
    public void bufferReaderTest() {
        try (BufferedReader bufferedReader = new BufferedReader(new FileReader("D:\\aa.txt"))) {
            String line;
            while ((line = bufferedReader.readLine())  != null) {
                // 处理每一行数据 .....
                processLines(line);
            }
        } catch (Exception e) {
            log.error(e.getMessage(), e);
        }
        print("BufferedReader");
    }

    @Test
    public void scannerTest() {
        try (Scanner scanner = new Scanner(new File(FILE_NAME))) {
            while (scanner.hasNextLine()) {
                // 处理每一行数据 .....
                String line = scanner.nextLine();
                processLines(line);
            }
        } catch (Exception e) {
            log.error(e.getMessage(), e);
        }
        print("Scanner");
    }

    @Test
    public void randomAccessFileTest() {

        try (RandomAccessFile accessFile = new RandomAccessFile(FILE_NAME, "r")) {
            String line;
            while ((line = accessFile.readLine()) != null) {
                // 处理每一行数据 .....
                processLines(line);
            }
        } catch (Exception e) {
            log.error(e.getMessage(), e);
        }
        print("RandomAccessFile");
    }


    @Test
    public void filesTest() {
        try {
            List<String> lines = Files.readAllLines(Paths.get(FILE_NAME));
//            lines.forEach(line -> {
//                // 处理每一行数据 .....
//                processLines(line);
//            });
            // 处理每一行数据 .....,方法引用更简洁
            lines.forEach(this::processLines);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
        }
        print("Files.readAllLines");
    }

    private void print(String name) {
        log.info("************* {} *******************", name);
        StringMap.forEach((k, v) -> {
            if (v != 1) {
               log.info("ip: {} count: {}", k, v);
            }
        });
        StringMap.clear();
    }

    private void processLines(String line) {
        String[] subLine = line.split(" ");
        String ip = subLine[subLine.length - 1];
        if (StringMap.containsKey(ip)) {
            Integer integer = StringMap.get(ip);
            StringMap.put(ip, integer + 1);
        } else {
            StringMap.put(ip, 1);
        }
    }
}

测试数据

2023-04-14 09:50:51,211 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 192.168.8.172
2023-04-14 09:50:51,211 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 172.31.106.64
2023-04-14 09:50:51,212 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 172.31.106.64
2023-04-14 09:50:51,212 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 172.31.106.69
2023-04-14 09:50:51,212 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 192.168.8.159
2023-04-14 09:50:51,212 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 192.168.8.161
2023-04-14 09:50:51,213 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 172.31.93.68
2023-04-14 09:50:51,213 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 192.168.8.186
2023-04-14 09:50:51,213 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 172.31.93.74
2023-04-14 09:50:51,213 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 172.31.106.64
2023-04-14 09:50:51,214 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 172.31.106.64
2023-04-14 09:50:51,214 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 172.31.106.95
2023-04-14 09:50:51,214 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 172.31.106.87
2023-04-14 09:50:51,214 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 172.31.93.127
2023-04-14 09:50:51,215 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 172.31.106.91
2023-04-14 09:50:51,215 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 172.31.93.115
2023-04-14 09:50:51,216 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 192.168.8.198
2023-04-14 09:50:51,216 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 172.31.106.105
2023-04-14 09:50:51,216 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 172.31.106.60
2023-04-14 09:50:51,216 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 172.31.106.60
2023-04-14 09:50:51,217 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 172.31.106.77
2023-04-14 09:50:51,217 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 172.31.93.125
2023-04-14 09:50:51,217 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 172.31.106.60
2023-04-14 09:50:51,217 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 192.168.8.173
2023-04-14 09:50:51,218 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 172.31.106.129
2023-04-14 09:50:51,218 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 192.168.8.208
2023-04-14 09:50:51,218 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 192.168.8.211
2023-04-14 09:50:51,218 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 172.31.106.63
2023-04-14 09:50:51,219 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 192.168.8.170
2023-04-14 09:50:51,219 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 192.168.8.195
2023-04-14 09:50:51,219 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 192.168.8.181
2023-04-14 09:50:51,219 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 192.168.8.180
2023-04-14 09:50:51,220 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 172.31.106.61
2023-04-14 09:50:51,220 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 192.168.8.201
2023-04-14 09:50:51,220 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 172.31.106.90
2023-04-14 09:50:51,220 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 172.31.93.26
2023-04-14 09:50:51,221 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 192.168.8.200
2023-04-14 09:50:51,221 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 172.31.106.126
2023-04-14 09:50:51,221 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 192.168.8.192
2023-04-14 09:50:51,221 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 172.31.106.96
2023-04-14 09:50:51,221 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 172.31.93.59
2023-04-14 09:50:51,222 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 172.31.93.50
2023-04-14 09:50:51,222 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 172.31.106.64
2023-04-14 09:50:51,222 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 172.31.106.64
2023-04-14 09:50:51,223 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 172.31.106.125
2023-04-14 09:50:51,223 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 172.31.106.82
2023-04-14 09:50:51,223 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 192.168.8.150
2023-04-14 09:50:51,223 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 192.168.8.209
2023-04-14 09:50:51,224 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 172.31.106.170
2023-04-14 09:50:51,224 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 172.31.93.51
2023-04-14 09:50:51,224 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 192.168.8.152
2023-04-14 09:50:51,224 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 172.31.93.21
2023-04-14 09:50:51,224 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 172.31.106.71
2023-04-14 09:50:51,225 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 172.31.106.88
2023-04-14 09:50:51,225 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 192.168.8.188
2023-04-14 09:50:51,225 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 192.168.8.187
2023-04-14 09:50:51,225 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 172.31.106.81
2023-04-14 09:50:51,226 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 192.168.8.155
2023-04-14 09:50:51,226 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 172.31.93.57
2023-04-14 09:50:51,226 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 192.168.8.148
2023-04-14 09:50:51,226 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 192.168.8.156
2023-04-14 09:50:51,226 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 192.168.8.154
2023-04-14 09:50:51,227 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 192.168.8.146
2023-04-14 09:50:51,227 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 192.168.8.160
2023-04-14 09:50:51,227 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 172.31.106.60
2023-04-14 09:50:51,227 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 172.31.93.123
2023-04-14 09:50:51,227 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 172.31.106.60
2023-04-14 09:50:51,228 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 192.168.8.184
2023-04-14 09:50:51,228 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 192.168.8.151
2023-04-14 09:50:51,228 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 192.168.8.182
2023-04-14 09:50:51,229 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 172.31.93.113
2023-04-14 09:50:51,229 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 172.31.106.89
2023-04-14 09:50:51,229 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 192.168.8.191
2023-04-14 09:50:51,229 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 192.168.8.205
2023-04-14 09:50:51,229 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 172.31.106.60
2023-04-14 09:50:51,230 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 172.31.106.74
2023-04-14 09:50:51,230 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 172.31.106.127
2023-04-14 09:50:51,230 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 192.168.8.157
2023-04-14 09:50:51,230 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 192.168.8.165
2023-04-14 09:50:51,231 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 172.31.93.122
2023-04-14 09:50:51,231 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 192.168.8.162
2023-04-14 09:50:51,231 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 192.168.8.183
2023-04-14 09:50:51,231 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 192.168.8.202
2023-04-14 09:50:51,232 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 192.168.8.166
2023-04-14 09:50:51,232 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 172.31.106.64
2023-04-14 09:50:51,234 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 192.168.8.210
2023-04-14 09:50:51,234 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 172.31.106.93
2023-04-14 09:50:51,234 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 192.168.8.171
2023-04-14 09:50:51,234 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 192.168.8.204
2023-04-14 09:50:51,235 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 192.168.8.207
2023-04-14 09:50:51,235 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 192.168.8.199
2023-04-14 09:50:51,235 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 172.31.106.124
2023-04-14 09:50:51,235 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 172.31.106.64
2023-04-14 09:50:51,236 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 172.31.106.123
2023-04-14 09:50:51,236 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 172.31.106.107
2023-04-14 09:50:51,236 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 192.168.8.169
2023-04-14 09:50:51,236 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 172.31.106.76
2023-04-14 09:50:51,236 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 172.31.106.94
2023-04-14 09:50:51,237 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 192.168.8.176
2023-04-14 09:50:51,237 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 172.31.93.24
2023-04-14 09:50:51,237 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 192.168.8.177
2023-04-14 09:50:51,237 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 172.31.93.23
2023-04-14 09:50:51,238 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 192.168.8.149
2023-04-14 09:50:51,238 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 172.31.106.75
2023-04-14 09:50:51,238 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 172.31.106.62
2023-04-14 09:50:51,239 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 172.31.106.64
2023-04-14 09:50:51,239 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 172.31.106.64
2023-04-14 09:50:51,239 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 172.31.106.70
2023-04-14 09:50:51,239 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 192.168.8.197
2023-04-14 09:50:51,239 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 172.31.106.60
2023-04-14 09:50:51,240 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 192.168.8.174
2023-04-14 09:50:51,240 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 172.31.93.114
2023-04-14 09:50:51,240 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 172.31.93.121
2023-04-14 09:50:51,240 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 192.168.8.189
2023-04-14 09:50:51,241 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 172.31.106.106
2023-04-14 09:50:51,241 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 172.31.93.126
2023-04-14 09:50:51,241 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 192.168.8.153
2023-04-14 09:50:51,241 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 192.168.8.167
2023-04-14 09:50:51,242 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 172.31.106.60
2023-04-14 09:50:51,242 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 192.168.8.190
2023-04-14 09:50:51,242 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 192.168.8.175
2023-04-14 09:50:51,242 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 192.168.8.206
2023-04-14 09:50:51,243 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 172.31.106.108
2023-04-14 09:50:51,243 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 172.31.93.112
2023-04-14 09:50:51,243 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 192.168.8.194
2023-04-14 09:50:51,243 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 172.31.93.25
2023-04-14 09:50:51,244 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 192.168.8.185
2023-04-14 09:50:51,244 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 192.168.8.179
2023-04-14 09:50:51,244 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 172.31.106.60
2023-04-14 09:50:51,244 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 172.31.106.64
2023-04-14 09:50:51,245 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 172.31.93.117
2023-04-14 09:50:51,245 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 172.31.106.64
2023-04-14 09:50:51,245 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 192.168.8.193
2023-04-14 09:50:51,245 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 172.31.106.92
2023-04-14 09:50:51,245 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 192.168.8.147
2023-04-14 09:50:51,246 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 172.31.93.116
2023-04-14 09:50:51,246 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 172.31.106.101
2023-04-14 09:50:51,246 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 192.168.8.196
2023-04-14 09:50:51,246 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 192.168.8.203
2023-04-14 09:50:51,246 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 172.31.106.86
2023-04-14 09:50:51,247 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 192.168.8.163
2023-04-14 09:50:51,247 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 192.168.8.178
2023-04-14 09:50:51,247 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 172.31.93.67
2023-04-14 09:50:51,247 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 172.31.106.97
2023-04-14 09:50:51,248 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 192.168.8.145
2023-04-14 09:50:51,248 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 192.168.8.158
2023-04-14 09:50:51,248 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 172.31.93.124
2023-04-14 09:50:51,248 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 172.31.93.111
2023-04-14 09:50:51,248 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 172.31.93.99
2023-04-14 09:50:51,249 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 172.31.106.128
2023-04-14 09:50:51,249 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 192.168.8.168
2023-04-14 09:50:51,249 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 172.31.93.128
2023-04-14 09:50:51,249 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 172.31.93.22
2023-04-14 09:50:51,252 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 192.168.8.164

到了这里,关于java 逐行读取文件(读取文件每一行、按行读取文件)附带示例代码的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • Golang 按行读取文件的 3 种方法

    Golang 是一种现代的编程语言,它具有高效、简洁和可扩展等特点,因此在各种领域广泛应用。在 Golang 中,读取文件是一个常见的操作。在本篇技术博客中,我将介绍如何在 Golang 中按行读取文件。 Golang 中有一个 bufio 包,它提供了 Scanner 类型,可以方便地按行读取文件。我

    2024年02月09日
    浏览(43)
  • Golang 按行读取文件的三种方法

    Golang 是一种现代的编程语言,它具有高效、简洁和可扩展等特点,因此在各种领域广泛应用。在 Golang 中,读取文件是一个常见的操作。在本篇技术博客中,我将介绍如何在 Golang 中按行读取文件。 Golang 中有一个 bufio 包,它提供了 Scanner 类型,可以方便地按行读取文件。我

    2024年02月08日
    浏览(56)
  • C 语言文件读取全指南:打开、读取、逐行输出

    要从文件读取,可以使用 r 模式: 这将使 filename.txt 打开以进行读取。 在 C 中读取文件需要一点工作。坚持住!我们将一步一步地指导您。 接下来,我们需要创建一个足够大的字符串来存储文件的内容。 例如,让我们创建一个可以存储多达 100 个字符的字符串: 为了读取

    2024年02月03日
    浏览(39)
  • c++多线程按行读取同一个每行长度不规则文件

    对于非常大的比如上百G的大文件读取,单线程读是非常非常慢的,需要考虑用多线程读,多个线程读同一个文件时不用加锁的,每个线程打开一个独立的文件句柄 先打开一个文件句柄,获取整个文件大小 file_size 确定要采用线程读取的部分大小 read_size 和多线程的个数 thread_num ,算出

    2024年03月09日
    浏览(48)
  • Linux从文件中逐行读取文件名并将匹配的文件复制到指定目录

    问题应该算挺常见的但是一句话还挺难说清楚,所以百度特别难搜。 场景就是,有一堆以员工名称命名的文件(名称可能还有字母数字等前后缀),现在给定一个员工清单,需要从这些文件中筛选出员工清单上列出的员工的文件,并复制到另外一个目录中。 输入: 1. 许多文

    2024年02月10日
    浏览(60)
  • Python——读取txt文件每一行数据

    【Python-数据读取】读取txt文件每一行数据生成列表

    2024年02月11日
    浏览(72)
  • 一行python命令让手机读取电脑文件_python手机端查看文件

    先自我介绍一下,小编浙江大学毕业,去过华为、字节跳动等大厂,目前阿里P7 深知大多数程序员,想要提升技能,往往是自己摸索成长,但自己不成体系的自学效果低效又漫长,而且极易碰到天花板技术停滞不前! 因此收集整理了一份《2024年最新Python全套学习资料》,初

    2024年04月25日
    浏览(37)
  • C++:ifstream通过getline读取文件会忽略最后一行空行

    getline是读取文件的常用函数,虽然使用简单,但是有一个较容易被忽视的问题,就是文件最后一行空行会被忽略。  假设文件abc.txt内容为 123 456 789 最后没有空行 运行程序输出: 1{123} 2{456} 3{789}  可以看到读到了3行完整的内容  假设文件abc.txt内容为 123 456 789 最后有一行空行

    2024年01月21日
    浏览(41)
  • (八)vtk常用类的常用函数介绍(附带代码示例)

    vtk中类的说明以及函数使用 https://vtk.org/doc/nightly/html/annotated.html InsertNextPoint(double, double, double):插入点。 InsertNextCell (vtkIdType npts, const vtkIdType *pts):插入单元。 SetRadius(double):设置球体半径,默认值为 0.5。 SetCenter(double, double, double):设置球体的中心,默认值为 0,0,0。 SetPh

    2024年02月07日
    浏览(36)
  • Java代码读取properties配置文件

    Properties 继承于 Hashtable。表示一个持久的属性集.属性列表中每个键及其对应值都是一个字符串。 HashTable是一个线程安全的类,它使用synchronized来锁住整张Hash表来实现线程安全,即每次锁住整张表让线程独占,相当于所有线程进行读写时都去竞争一把锁,导致效率非常低下。

    2024年02月02日
    浏览(70)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包