Java Path File Read nio readers(String path)

Here you can find the source of readers(String path)

Description

readers

License

Open Source License

Declaration

public static String[] readers(String path) throws IOException 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.io.BufferedReader;

import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;

import java.io.OutputStream;
import java.io.Reader;
import java.io.Writer;
import java.net.ServerSocket;
import java.net.Socket;
import java.nio.channels.Channel;
import java.util.ArrayList;
import java.util.List;

public class Main {
    public static String[] readers(String path) throws IOException {
        FileReader fileReader = new FileReader(path);
        BufferedReader fr = new BufferedReader(fileReader);
        String line = null;/*from   w ww  .  j ava2s .  c  o  m*/
        List<String> list = new ArrayList<>();
        while (null != (line = fr.readLine())) {
            list.add(line);
        }
        close(fileReader);
        return list.toArray(new String[] {});
    }

    public static void close(InputStream in) {
        if (null != in) {
            try {
                in.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

    public static void close(Socket socket) {
        if (null != socket) {
            if (!socket.isClosed()) {
                try {
                    socket.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }

    public static void close(ServerSocket socket) {
        if (null != socket) {
            if (!socket.isClosed()) {
                try {
                    socket.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }

    public static void close(OutputStream out) {
        if (null != out) {
            try {
                out.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

    public static void close(Reader reader) {
        if (null != reader) {
            try {
                reader.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

    public static void close(Writer writer) {
        if (null != writer) {
            try {
                writer.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

    public static void close(Channel channel) {
        if (null != channel) {
            if (channel.isOpen()) {
                try {
                    channel.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}

Related

  1. readAllLinesOrExit(Path path)
  2. readAndConsume(String filePath, Consumer consumer)
  3. readAsString(Path path)
  4. readAsString(String path)
  5. reader(String path)
  6. readFile(Path directory, String... parts)
  7. readFile(Path file)
  8. readFile(Path path)
  9. readFile(Path path)