All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.cschen1205.navigator.utils.FileUtils Maven / Gradle / Ivy

package com.github.cschen1205.navigator.utils;

import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.List;

import static java.util.stream.Collectors.toList;

/**
 * Created by cschen1205 on 12/8/15.
 */
public class FileUtils {
    public static List getLines(String fileName) {

        List lines = null;

        //Get file from resources folder
        ClassLoader classLoader = FileUtils.class.getClassLoader();


        try(BufferedReader reader = new BufferedReader(new InputStreamReader(classLoader.getResourceAsStream(fileName)))){
            lines = reader.lines().collect(toList());
        } catch (IOException e) {
            e.printStackTrace();
        }

        return lines;

    }

    public static File getResourceFile(String filename) {
        //Get file from resources folder
        ClassLoader classLoader = FileUtils.class.getClassLoader();

        return new File(classLoader.getResource(filename).getFile());
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy