Java InputStreamReader Read readFileAsArray(String path)

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

Description

read File As Array

License

Apache License

Declaration

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

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.io.BufferedReader;

import java.io.FileInputStream;

import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

public class Main {
    public static String[] readFileAsArray(String path) throws IOException {
        String[] result = new String[] {};
        InputStream in = new FileInputStream(path);
        BufferedReader reader = new BufferedReader(new InputStreamReader(in, "UTF-8"));
        String line = "";
        int i = 0;
        while ((line = reader.readLine()) != null) {
            line = line.trim();//from www.  j av  a2  s .  co m
            if (line == null || "".equals(line)) {
                continue;
            }
            result[i] = line;
        }
        reader.close();
        return result;
    }
}

Related

  1. readFile(String path)
  2. readFile(String path, String charset)
  3. readFile(ZipInputStream zin)
  4. readFileAddLine(String filePath, Object object)
  5. readFileAll(File file, String charsetName)
  6. readFileAsJson(String path)
  7. readFileAsList(String path)
  8. readFileByCharAsString(String path, String encode)
  9. readFileCharacters(File file, boolean fix)