package com.trs.project.file;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.Resource;
import org.springframework.core.io.ResourceLoader;
import org.springframework.stereotype.Component;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;

@Component
public class FileReaderResource {

    @Autowired
    ResourceLoader resourceLoader;

    public ArrayList<String> ReaderFile() throws IOException {
        Resource resource = resourceLoader.getResource("classpath:city.txt");
        InputStream is = resource.getInputStream();
        InputStreamReader isr = new InputStreamReader(is);
        BufferedReader br = new BufferedReader(isr);
        String data = null;
        ArrayList<String> arrayList = new ArrayList<String>();
        while((data = br.readLine()) != null) {
            arrayList.add(data);
        }
        br.close();
        isr.close();
        is.close();
        return arrayList;
    }
}
