Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.company;
- import java.io.*;
- import java.nio.charset.Charset;
- import java.util.ArrayList;
- import java.util.HashMap;
- import java.util.Map;
- import java.util.Scanner;
- public class Main
- {
- public static void aasd(String a){
- }
- public static void main(String[] args) {
- Scanner read = new Scanner(System.in);
- String workingDir = System.getProperty("user.dir");
- String filename;
- String line;
- Map<String,String> city_country = new HashMap<String,String>();
- boolean a = true;
- System.out.println("Current dir: "+workingDir);
- filename = read.next();
- try (
- InputStream fis = new FileInputStream(filename);
- InputStreamReader isr = new InputStreamReader(fis, Charset.forName("UTF-8"));
- BufferedReader br = new BufferedReader(isr);
- ) {
- while ((line = br.readLine()) != null) {
- if (a) {
- if (line.contains(",")) {
- String[] strings = line.split(",");
- city_country.put(strings[0], strings[1]);
- }
- }
- }
- } catch (FileNotFoundException e) {
- e.printStackTrace();
- } catch (IOException e) {
- e.printStackTrace();
- }
- a=true;
- while (a){
- System.out.print("Write the name of the city or write 'STOP' for end: ");
- String c =read.next();
- if ((c).equals("STOP"))
- a=false;
- if(a){
- if ((city_country.get(c)!=(null)))
- System.out.println("Country: "+city_country.get(c));
- else System.out.println("Country doesn't exist");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement