Hi i am new to Java working with files. I have got a text file called banking.txt
located in C:
but when i try put its content into an ArrayList
and print it prints out nothing. Is the file path i am using incorrect or is it something different?
import java.util.ArrayList;
import java.util.Scanner;
import java.io.*;
public class FileP {
public static void main(String[] args) throws FileNotFoundException {
Scanner read = new Scanner(new File("C:\\banking.txt"));
ArrayList<String> myList = new ArrayList<String>();
while(read.hasNextLine()) {
myList.add(read.nextLine());
}
System.out.println(myList);
}
}