32 lines
837 B
Java
32 lines
837 B
Java
package ClientApp;
|
|
import java.io.BufferedReader;
|
|
import java.io.FileReader;
|
|
import java.util.ArrayList;
|
|
import java.util.HashMap;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
public class FileToMap {
|
|
|
|
private Map<String, List<String>> mymap = new HashMap<>();
|
|
|
|
public Map<String, List<String>> getMap() {
|
|
try (FileReader fr = new FileReader("Elaborato_IS/src/Data/città.txt")) {
|
|
BufferedReader reader = new BufferedReader(fr);
|
|
String line, nation, city;
|
|
int pos;
|
|
while ((line = reader.readLine()) != null) {
|
|
pos = line.indexOf("@");
|
|
nation = line.substring(0, pos);
|
|
city = line.substring(pos + 1);
|
|
mymap.putIfAbsent(nation, new ArrayList<String>());
|
|
mymap.get(nation).add(city);
|
|
}
|
|
} catch (Exception e) {
|
|
System.out.println("Il file città.txt non esiste");
|
|
}
|
|
return mymap;
|
|
}
|
|
}
|
|
|
|
|