-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLoadUserAgent.java
53 lines (39 loc) · 1.05 KB
/
LoadUserAgent.java
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
import java.util.Random;
public class LoadUserAgent {
List<String> userAgents = new ArrayList<>();
public LoadUserAgent() {
BufferedReader br = null ;
try {
br = new BufferedReader(new FileReader(new File("user-agents.txt")));
String sCurrentline;
while((sCurrentline = br.readLine()) != null) {
userAgents.add(sCurrentline);
}
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally {
try {
br.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
public String getRandomUserAgent() {
Random rand = new Random();
return userAgents.get(rand.nextInt(userAgents.size()));
}
}