返回顶部
首页 > 资讯 > 后端开发 > JAVA >java 逐行读取文件(读取文件每一行、按行读取文件)附带示例代码
  • 428
分享到

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

javaIO 2023-09-11 15:09:22 428人浏览 薄情痞子
摘要

BufferedReader 最快的读取每一行 @Test public void bufferReaderTest() { try (BufferedReader buffere

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出现的次数

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;@Slf4jpublic 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.1722023-04-14 09:50:51,211 INFO  [SprinGContextShutdownHook] c.i.w.i.WEBSocketServiceImpl.onClosing(496) : connection close 172.31.106.642023-04-14 09:50:51,212 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 172.31.106.642023-04-14 09:50:51,212 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 172.31.106.692023-04-14 09:50:51,212 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 192.168.8.1592023-04-14 09:50:51,212 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 192.168.8.1612023-04-14 09:50:51,213 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 172.31.93.682023-04-14 09:50:51,213 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 192.168.8.1862023-04-14 09:50:51,213 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 172.31.93.742023-04-14 09:50:51,213 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 172.31.106.642023-04-14 09:50:51,214 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 172.31.106.642023-04-14 09:50:51,214 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 172.31.106.952023-04-14 09:50:51,214 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 172.31.106.872023-04-14 09:50:51,214 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 172.31.93.1272023-04-14 09:50:51,215 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 172.31.106.912023-04-14 09:50:51,215 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 172.31.93.1152023-04-14 09:50:51,216 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 192.168.8.1982023-04-14 09:50:51,216 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 172.31.106.1052023-04-14 09:50:51,216 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 172.31.106.602023-04-14 09:50:51,216 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 172.31.106.602023-04-14 09:50:51,217 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 172.31.106.772023-04-14 09:50:51,217 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 172.31.93.1252023-04-14 09:50:51,217 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 172.31.106.602023-04-14 09:50:51,217 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 192.168.8.1732023-04-14 09:50:51,218 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 172.31.106.1292023-04-14 09:50:51,218 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 192.168.8.2082023-04-14 09:50:51,218 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 192.168.8.2112023-04-14 09:50:51,218 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 172.31.106.632023-04-14 09:50:51,219 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 192.168.8.1702023-04-14 09:50:51,219 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 192.168.8.1952023-04-14 09:50:51,219 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 192.168.8.1812023-04-14 09:50:51,219 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 192.168.8.1802023-04-14 09:50:51,220 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 172.31.106.612023-04-14 09:50:51,220 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 192.168.8.2012023-04-14 09:50:51,220 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 172.31.106.902023-04-14 09:50:51,220 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 172.31.93.262023-04-14 09:50:51,221 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 192.168.8.2002023-04-14 09:50:51,221 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 172.31.106.1262023-04-14 09:50:51,221 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 192.168.8.1922023-04-14 09:50:51,221 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 172.31.106.962023-04-14 09:50:51,221 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 172.31.93.592023-04-14 09:50:51,222 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 172.31.93.502023-04-14 09:50:51,222 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 172.31.106.642023-04-14 09:50:51,222 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 172.31.106.642023-04-14 09:50:51,223 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 172.31.106.1252023-04-14 09:50:51,223 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 172.31.106.822023-04-14 09:50:51,223 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 192.168.8.1502023-04-14 09:50:51,223 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 192.168.8.2092023-04-14 09:50:51,224 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 172.31.106.1702023-04-14 09:50:51,224 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 172.31.93.512023-04-14 09:50:51,224 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 192.168.8.1522023-04-14 09:50:51,224 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 172.31.93.212023-04-14 09:50:51,224 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 172.31.106.712023-04-14 09:50:51,225 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 172.31.106.882023-04-14 09:50:51,225 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 192.168.8.1882023-04-14 09:50:51,225 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 192.168.8.1872023-04-14 09:50:51,225 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 172.31.106.812023-04-14 09:50:51,226 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 192.168.8.1552023-04-14 09:50:51,226 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 172.31.93.572023-04-14 09:50:51,226 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 192.168.8.1482023-04-14 09:50:51,226 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 192.168.8.1562023-04-14 09:50:51,226 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 192.168.8.1542023-04-14 09:50:51,227 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 192.168.8.1462023-04-14 09:50:51,227 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 192.168.8.1602023-04-14 09:50:51,227 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 172.31.106.602023-04-14 09:50:51,227 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 172.31.93.1232023-04-14 09:50:51,227 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 172.31.106.602023-04-14 09:50:51,228 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 192.168.8.1842023-04-14 09:50:51,228 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 192.168.8.1512023-04-14 09:50:51,228 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 192.168.8.1822023-04-14 09:50:51,229 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 172.31.93.1132023-04-14 09:50:51,229 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 172.31.106.892023-04-14 09:50:51,229 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 192.168.8.1912023-04-14 09:50:51,229 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 192.168.8.2052023-04-14 09:50:51,229 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 172.31.106.602023-04-14 09:50:51,230 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 172.31.106.742023-04-14 09:50:51,230 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 172.31.106.1272023-04-14 09:50:51,230 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 192.168.8.1572023-04-14 09:50:51,230 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 192.168.8.1652023-04-14 09:50:51,231 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 172.31.93.1222023-04-14 09:50:51,231 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 192.168.8.1622023-04-14 09:50:51,231 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 192.168.8.1832023-04-14 09:50:51,231 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 192.168.8.2022023-04-14 09:50:51,232 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 192.168.8.1662023-04-14 09:50:51,232 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 172.31.106.642023-04-14 09:50:51,234 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 192.168.8.2102023-04-14 09:50:51,234 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 172.31.106.932023-04-14 09:50:51,234 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 192.168.8.1712023-04-14 09:50:51,234 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 192.168.8.2042023-04-14 09:50:51,235 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 192.168.8.2072023-04-14 09:50:51,235 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 192.168.8.1992023-04-14 09:50:51,235 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 172.31.106.1242023-04-14 09:50:51,235 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 172.31.106.642023-04-14 09:50:51,236 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 172.31.106.1232023-04-14 09:50:51,236 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 172.31.106.1072023-04-14 09:50:51,236 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 192.168.8.1692023-04-14 09:50:51,236 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 172.31.106.762023-04-14 09:50:51,236 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 172.31.106.942023-04-14 09:50:51,237 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 192.168.8.1762023-04-14 09:50:51,237 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 172.31.93.242023-04-14 09:50:51,237 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 192.168.8.1772023-04-14 09:50:51,237 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 172.31.93.232023-04-14 09:50:51,238 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 192.168.8.1492023-04-14 09:50:51,238 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 172.31.106.752023-04-14 09:50:51,238 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 172.31.106.622023-04-14 09:50:51,239 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 172.31.106.642023-04-14 09:50:51,239 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 172.31.106.642023-04-14 09:50:51,239 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 172.31.106.702023-04-14 09:50:51,239 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 192.168.8.1972023-04-14 09:50:51,239 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 172.31.106.602023-04-14 09:50:51,240 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 192.168.8.1742023-04-14 09:50:51,240 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 172.31.93.1142023-04-14 09:50:51,240 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 172.31.93.1212023-04-14 09:50:51,240 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 192.168.8.1892023-04-14 09:50:51,241 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 172.31.106.1062023-04-14 09:50:51,241 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 172.31.93.1262023-04-14 09:50:51,241 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 192.168.8.1532023-04-14 09:50:51,241 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 192.168.8.1672023-04-14 09:50:51,242 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 172.31.106.602023-04-14 09:50:51,242 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 192.168.8.1902023-04-14 09:50:51,242 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 192.168.8.1752023-04-14 09:50:51,242 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 192.168.8.2062023-04-14 09:50:51,243 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 172.31.106.1082023-04-14 09:50:51,243 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 172.31.93.1122023-04-14 09:50:51,243 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 192.168.8.1942023-04-14 09:50:51,243 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 172.31.93.252023-04-14 09:50:51,244 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 192.168.8.1852023-04-14 09:50:51,244 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 192.168.8.1792023-04-14 09:50:51,244 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 172.31.106.602023-04-14 09:50:51,244 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 172.31.106.642023-04-14 09:50:51,245 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 172.31.93.1172023-04-14 09:50:51,245 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 172.31.106.642023-04-14 09:50:51,245 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 192.168.8.1932023-04-14 09:50:51,245 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 172.31.106.922023-04-14 09:50:51,245 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 192.168.8.1472023-04-14 09:50:51,246 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 172.31.93.1162023-04-14 09:50:51,246 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 172.31.106.1012023-04-14 09:50:51,246 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 192.168.8.1962023-04-14 09:50:51,246 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 192.168.8.2032023-04-14 09:50:51,246 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 172.31.106.862023-04-14 09:50:51,247 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 192.168.8.1632023-04-14 09:50:51,247 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 192.168.8.1782023-04-14 09:50:51,247 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 172.31.93.672023-04-14 09:50:51,247 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 172.31.106.972023-04-14 09:50:51,248 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 192.168.8.1452023-04-14 09:50:51,248 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 192.168.8.1582023-04-14 09:50:51,248 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 172.31.93.1242023-04-14 09:50:51,248 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 172.31.93.1112023-04-14 09:50:51,248 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 172.31.93.992023-04-14 09:50:51,249 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 172.31.106.1282023-04-14 09:50:51,249 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 192.168.8.1682023-04-14 09:50:51,249 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 172.31.93.1282023-04-14 09:50:51,249 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 172.31.93.222023-04-14 09:50:51,252 INFO  [SpringContextShutdownHook] c.i.w.i.WebSocketServiceImpl.onClosing(496) : connection close 192.168.8.164

来源地址:https://blog.csdn.net/qq_40965479/article/details/130194793

--结束END--

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

本文链接: https://lsjlt.com/news/403314.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

猜你喜欢
  • java 逐行读取文件(读取文件每一行、按行读取文件)附带示例代码
    BufferedReader 最快的读取每一行 @Test public void bufferReaderTest() { try (BufferedReader buffere...
    99+
    2023-09-11
    java IO
  • Java怎么按行读取文件
    在Java中,可以使用BufferedReader来按行读取文件。下面是一个简单的例子: import java.io.Buffer...
    99+
    2024-03-05
    Java
  • php如何逐行读取文件
    这篇文章主要讲解了“php如何逐行读取文件”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习“php如何逐行读取文件”吧!有一个名为“test.txt”的文本文件,里面的内容为:我们如何逐行读取文...
    99+
    2023-06-20
  • linux怎么逐行读取文件
    在Linux中,可以使用以下几种方法逐行读取文件: 使用cat命令配合管道和while循环逐行读取文件: cat filenam...
    99+
    2024-02-29
    linux
  • java怎么逐行读取文件内容
    在Java中,我们可以使用BufferedReader类来逐行读取文件内容。以下是一个示例代码: import java.io.Bu...
    99+
    2024-03-05
    java
  • Python按行读取文件的实现方法【小文件和大文件读取】
    本文实例讲述了Python按行读取文件的实现方法。分享给大家供大家参考,具体如下: 小文件: #coding=utf-8 #author: walker #date: 2013-12-30 #funct...
    99+
    2022-06-04
    文件 大文件 方法
  • node.js实现逐行读取文件内容的代码
    在此之前先介绍一个逐行读取文件内容NPM:https://github.com/nickewing/line-reader,需要的朋友可以看看。 直接上代码: function readLines(in...
    99+
    2022-06-04
    代码 文件 内容
  • shell怎么循环读取文件每一行
    在shell脚本中,可以使用`while`循环结合`read`命令来逐行读取文件内容。以下是一个示例:```shell#!/bin/...
    99+
    2023-08-14
    shell
  • Python怎么实现逐行读取文本文件
    这篇文章主要讲解了“Python怎么实现逐行读取文本文件”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习“Python怎么实现逐行读取文本文件”吧!在Python 中有几种方法可以读取文本文件。...
    99+
    2023-06-22
  • Python如何实现逐行读取文本文件
    目录Python 中的 open() 函数是什么文件名和正确路径open() 中的可选模式参数Python 中 open() 函数的其他参数Python 中的 read() 方法Py...
    99+
    2024-04-02
  • java怎么逐行读取文本
    在Java中,可以使用BufferedReader类逐行读取文本文件。以下是一个示例代码: import java.io.Buffe...
    99+
    2024-02-29
    java
  • Shell逐行读取文件的4种方法
    在Linux中有很多方法逐行读取一个文件的方法,其中最常用的就是下面的脚本里的方法,而且是效率最高,使用最多的方法。为了给大家一个直观的感受,我们将通过生成一个大的文件的方式来检验各种方法的执行效率。 方...
    99+
    2022-06-04
    种方法 文件 Shell
  • node.jsreadline和line-reader逐行读取文件方法
    逐行读取文件的能力允许我们读取大文件,而无需将其全部存储到内存中。它有助于节省资源和提高应用程序的效率。 它允许我们寻找所需的信息,一旦找到了相关的信息,我们可以停止搜索过程,可以防...
    99+
    2022-11-13
    node.js readline 逐行读取文件方法 node.js line-reader逐行读取文件方法 node.js逐行读取文件方法 node.js line-reader库安装方法
  • perl怎么读取文件的每一行内容
    在Perl中,可以使用<FILEHANDLE>的方式来读取文件的每一行内容。具体步骤如下: 打开文件并将文件句柄赋值给...
    99+
    2024-04-02
  • 怎么在python中按行读取文件
    这期内容当中小编将会给大家带来有关怎么在python中按行读取文件,文章内容丰富且以专业的角度为大家分析和叙述,阅读完这篇文章希望大家可以有所收获。1、read 方法默认会把文件的 所有内容一次性读取到内存如果文件太大,对内存的占用会非常严...
    99+
    2023-06-15
  • 如何在 PHP 中逐行读取一个大文件
    在本文中,我们将介绍在 PHP 中逐行读取一个大文件的方法。 使用 fgets() 函数 使用 file() 函数 使用 stream_get_line() 函数 在 ...
    99+
    2024-02-27
  • 怎么在Shell脚本中逐行读取文件
    小编给大家分享一下怎么在Shell脚本中逐行读取文件,相信大部分人都还不怎么了解,因此分享这篇文章给大家参考一下,希望大家阅读完这篇文章后大有收获,下面让我们一起去了解一下吧!方法一、使用输入重定向逐行读取文件的最简单方法是在while循环...
    99+
    2023-06-17
  • 怎样在Shell脚本中逐行读取文件
    本篇文章给大家分享的是有关怎样在Shell脚本中逐行读取文件,小编觉得挺实用的,因此分享给大家学习,希望大家阅读完这篇文章后可以有所收获,话不多说,跟着小编一起来看看吧。方法一、使用输入重定向逐行读取文件的最简单方法是在while循环中使用...
    99+
    2023-06-28
  • python逐行读取文件的方法是什么
    Python提供了多种方法来逐行读取文件。以下是其中几种常见的方法: 使用readline()方法:该方法逐行读取文件,并返回一个...
    99+
    2024-02-29
    python
  • 在node.js中一次读取一行文件?
    问题内容 我正在尝试一次一行读取一个大文件。我在 Quora 上发现了一个涉及该主题的问题,但我缺少一些联系来使整个事情融为一体。 var Lazy=require("lazy");...
    99+
    2024-02-06
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作