-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReadFile.java
More file actions
28 lines (25 loc) · 865 Bytes
/
ReadFile.java
File metadata and controls
28 lines (25 loc) · 865 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
package com.baseballaholic.CalloutsMod;
import java.io.File; // Import the File class
import java.io.FileNotFoundException; // Import this class to handle errors
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner; // Import the Scanner class to read text files
public class ReadFile {
public static String[] Read() {
List<String> data = new ArrayList<String>();
try {
File myObj = new File("CoordData.txt");
Scanner myReader = new Scanner(myObj);
while (myReader.hasNextLine()) {
String d = myReader.nextLine();
data.add(d);
System.out.println(d);
}
myReader.close();
} catch (FileNotFoundException e) {
System.out.println("An error occurred.");
e.printStackTrace();
}
return data.toArray(new String[data.size()]);
}
}