looping files java code example
Example: java loop through file
/*
* FileLooper reads data from file and adds it to an ArrayList class
* for later use.
*/
import java.util.*;
import java.io.*;
class FileLooper {
public static void main(String [] args) {
String fileName = "file.txt";
ArrayList<String> fileData = new ArrayList<>();
Scanner file = new Scanner(new File(fileName));
while (file.hasNext()) {
fileData.add(file.next());
}
}
}