31 lines
848 B
Java
31 lines
848 B
Java
![]() |
package model;
|
||
|
|
||
|
import com.fasterxml.jackson.databind.JsonNode;
|
||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||
|
|
||
|
import java.io.File;
|
||
|
import java.io.IOException;
|
||
|
import java.util.List;
|
||
|
import java.util.stream.Collectors;
|
||
|
|
||
|
// WYKORZYSTANIE STRUMIENIA
|
||
|
public class CityNames {
|
||
|
public static void cityNamesRead(String filePath) {
|
||
|
ObjectMapper objectMapper = new ObjectMapper();
|
||
|
|
||
|
try {
|
||
|
JsonNode jsonArray = objectMapper.readTree(new File(filePath));
|
||
|
|
||
|
List<String> cityNames = jsonArray
|
||
|
.findValuesAsText("name")
|
||
|
.stream()
|
||
|
.collect(Collectors.toList());
|
||
|
|
||
|
System.out.println("Dostępne miasta:");
|
||
|
cityNames.forEach(System.out::println);
|
||
|
|
||
|
} catch (IOException e) {
|
||
|
e.printStackTrace();
|
||
|
}
|
||
|
}
|
||
|
}
|