-
Notifications
You must be signed in to change notification settings - Fork 0
/
Wiki.java
47 lines (35 loc) · 1.23 KB
/
Wiki.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
package ChatBot;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.net.*;
import java.io.*;
public class Wiki {
public void search(String key) throws InterruptedException {
URL url;
try {
// get URL content
String a="https://en.wikipedia.org/wiki/"+key;
url = new URL(a);
URLConnection conn = url.openConnection();
// open the stream and put it into BufferedReader
BufferedReader br = new BufferedReader(
new InputStreamReader(conn.getInputStream()));
Path dest=Paths.get("src/ChatBot/new");
String inputLine;
BufferedWriter writer=Files.newBufferedWriter(dest);
while ((inputLine = br.readLine()) != null) {
writer.write(inputLine);
writer.newLine();
}
br.close();
ExecuteShellCommand ex=new ExecuteShellCommand(key);
ex.executeCommands();
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}