Advertisement
Guest User

Untitled

a guest
Sep 23rd, 2019
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.17 KB | None | 0 0
  1. package com.company;
  2.  
  3. import java.io.*;
  4. import java.util.ArrayList;
  5. import java.util.Properties;
  6. import java.util.Scanner;
  7.  
  8.  
  9. public class Main {
  10.  
  11.     public static final String PATH_TO_DATA = "C:\\Users\\elise\\IdeaProjects\\chat\\src\\com\\company\\askWords";
  12.     public static final String PATH_TO_ANSWERS = "C:\\Users\\elise\\IdeaProjects\\chat\\src\\com\\company\\baseWords";
  13.  
  14.     public static void main(String[] args) {
  15.         FileInputStream fileInputStream = null;
  16.         FileInputStream fileInputStream_A = null;
  17.         Properties prop = new Properties();
  18.         Properties prop_a = new Properties();
  19.         ArrayList<String> question = new ArrayList<>();
  20.         ArrayList<String> answer = new ArrayList<>();
  21.  
  22.         try {
  23.             //обращаемся к файлу и получаем данные
  24.             fileInputStream = new FileInputStream(PATH_TO_DATA);
  25.             prop.load(fileInputStream);
  26.  
  27.             fileInputStream_A = new FileInputStream(PATH_TO_ANSWERS);
  28.             prop_a.load(fileInputStream_A);
  29.  
  30.             Scanner in = new Scanner(System.in);
  31.             System.out.print("Input a word: ");
  32.             // то что нужно разделить
  33.             String s = in.nextLine();
  34.             //
  35.             question.add(prop.getProperty(s));
  36.  
  37.             for (int i = 0; i < question.size(); i++) {
  38.                 answer.add(prop_a.getProperty(question.get(i)));
  39.             }
  40.  
  41.             System.out.println(answer);
  42.  
  43.         } catch (IOException e) {
  44.             System.out.println("Ошибка в программе: файл не обнаружен");
  45.             e.printStackTrace();
  46.         } finally {
  47.             if (fileInputStream != null) {
  48.                 try {
  49.                     fileInputStream.close();
  50.                 } catch (IOException e) {
  51.                     e.printStackTrace();
  52.                 }
  53.                 if (fileInputStream_A != null) {
  54.                     try {
  55.                         fileInputStream_A.close();
  56.                     } catch (IOException e) {
  57.                         e.printStackTrace();
  58.                     }
  59.                 }
  60.             }
  61.         }
  62.     }
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement