Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.BufferedReader;
- import java.io.FileReader;
- import java.io.IOException;
- import java.util.HashMap;
- import java.util.Map;
- import java.util.Scanner;
- public class Message
- {
- public static void main (String[] args) throws IOException {
- // a new BufferedReader to load .txt's
- Scanner scanner = new Scanner(System.in);
- BufferedReader brUser = new BufferedReader(new FileReader("merged.txt"));
- Map<String, String> map = new HashMap<String, String>();
- // Read username.txt line by line
- for(String line; (line = brUser.readLine()) != null;) {
- String[] s = line.split(" ");
- map.put(s[0], s[1]);
- }
- brUser.close();
- System.out.println("Enter username (exit to stop)");
- String value = scanner.nextLine();
- while(!"exit".equals(value))
- {
- if(map.containsKey(value))
- {
- System.out.println("Message: " + map.get(value));
- }
- else if(!map.containsKey(value))
- {
- System.out.println("User does not exist");
- }
- value = scanner.nextLine();
- }
- scanner.close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement