-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReadFile.java
More file actions
34 lines (27 loc) · 913 Bytes
/
ReadFile.java
File metadata and controls
34 lines (27 loc) · 913 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
29
30
31
32
33
34
import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Scanner;
/*
This class reads the specified file containing the lists of websites and returns it in an ArrayList
*/
public class ReadFile {
public ArrayList returnList(String fileName) throws FileNotFoundException {
ArrayList<String> websites = new ArrayList();
try {
Scanner scanner = new Scanner(new File(fileName));
while (scanner.hasNext()) {
String website = scanner.next();
if(website.substring(website.length()-1).equals("/"))
{
website = website.substring(0, website.length()-1);
}
websites.add(website);
}
}
catch (Exception e){
System.out.println("File not found");
}
return websites;
}
}