Advertisement
test1234541234098234

Untitled

Mar 1st, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. import java.io.BufferedReader;
  2. import java.io.FileReader;
  3. import java.io.IOException;
  4. import java.util.HashMap;
  5. import java.util.Map;
  6. import java.util.Scanner;
  7.  
  8. public class Message
  9. {
  10.  
  11. public static void main (String[] args) throws IOException {
  12.  
  13. // a new BufferedReader to load .txt's
  14. Scanner scanner = new Scanner(System.in);
  15.  
  16. BufferedReader brUser = new BufferedReader(new FileReader("merged.txt"));
  17. Map<String, String> map = new HashMap<String, String>();
  18.  
  19. // Read username.txt line by line
  20. for(String line; (line = brUser.readLine()) != null;) {
  21. String[] s = line.split(" ");
  22. map.put(s[0], s[1]);
  23. }
  24. brUser.close();
  25. System.out.println("Enter username (exit to stop)");
  26. String value = scanner.nextLine();
  27. while(!"exit".equals(value))
  28. {
  29. if(map.containsKey(value))
  30. {
  31. System.out.println("Message: " + map.get(value));
  32. }
  33. else if(!map.containsKey(value))
  34. {
  35. System.out.println("User does not exist");
  36. }
  37. value = scanner.nextLine();
  38.  
  39.  
  40. }
  41. scanner.close();
  42. }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement