using Scanner.findAll to get all the download links from a json file.
Transcribed from the original LinkedIn image post.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
| import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
import java.util.regex.MatchResult;
class Day18 {
public static void main(String[] args) {
File file = new File("/home/mohibulhasan/Downloads/data.json");
String urlRegex = "\"(https?|ftp|file)://[-a-zA-Z0-9+&@#/%?=~_|!:,.;]*[-a-zA-Z0-9+&@#/%=~_|]\"";
String propertyName = "\"downloadLink\":\"";
try (Scanner scanner = new Scanner(file)) {
scanner.findAll(propertyName + urlRegex)
.map(MatchResult::group)
.forEach(System.out::println);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
}
|
The original LinkedIn graphic is preserved below.
