//*******************************************************************************
// Read a file using Java "nio" package 
// Read entire file into a List                          
//*******************************************************************************
import java.nio.file.*;                             //import nio.file package
import java.nio.charset.*;                          //used for Charset (if used)
import java.util.*;                                 //used for the List class

public class ReadIntoList  
{
    public static void main(String[] args)
    {
        try { 
            Path infile = Paths.get("/home/s/sultans/web/java/demo/8inpout/data/temp.txt");

            List<String> lines = Files.readAllLines(infile);    //read all lines into a String List

//          List<String> lines = Files.readAllLines(infile, Charset.forName("UTF-8"));	  //or UTF-16, etc.       


            int nLines = lines.size();                          //number of lines
            String[] array = new String[nLines];                //create an array of same number of lines 

            int i=0;
            for(String line : lines)                            //for each line in lines List
               array[i++] = line;                               //copy into array

            for(String line : array)                            //for each line in lines List
               System.out.println(line);                        //print the line   
        }
        catch(Exception e) 
        {
            System.out.print(e);                                //print the exception
            e.printStackTrace();                                //print trace dump
        }
    }
}