hbthlw
8/16/2018 - 4:32 AM

[Read File Line By Line] #java

[Read File Line By Line] #java

package com.pay.readlog;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

import java.io.BufferedReader;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.stream.Stream;

@SpringBootApplication
public class ReadLogApplication {

    public static void main(String[] args) {
        if (args.length < 1) {
            System.exit(1);
        }
        System.out.println(args[0]);
        SpringApplication.run(ReadLogApplication.class, args);

        new ReadLogApplication().readFile(args[0]);
    }

    private void readFile(String fileName) {

        try (BufferedReader reader = Files.newBufferedReader(Paths.get(fileName))) {

            String line;

            while ((line = reader.readLine()) != null) {
                System.out.println(line);
            }

        } catch (IOException e) {
            e.printStackTrace();
        }

    }
}