Advertisement
Guest User

Untitled

a guest
Dec 10th, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.72 KB | None | 0 0
  1. private enum Parameters {
  2.         input, param, output, num
  3.     }
  4.  
  5.     String fileIn = null;
  6. String stringNum = null;
  7.     int num = 0;
  8. private static final String GrammarEqual = "=";
  9.     private static final Map<Parameters, String> map;
  10.  
  11.     static {
  12.         map = new HashMap<>();
  13.  
  14.         map.put(Parameters.input, "INPUT_FILE");
  15.         map.put(Parameters.param, "INPUT_PARAM");
  16.         map.put(Parameters.output, "OUTPUT_FILE");
  17.         map.put(Parameters.num, "NUM");
  18.     }
  19. private void readConfig(String configFile) throws IOException {
  20.         FileInputStream fin = new FileInputStream(configFile);
  21.         String str;
  22.         String strDelete = "\n"; //Разделение
  23.         byte[] buffer = new byte[fin.available()];
  24.         fin.read(buffer);
  25.         //str = buffer.toString();
  26.         str = new String(buffer);
  27.         str = str.replaceAll(" ", "");
  28.         str = str.replaceAll("\r", "");
  29.         String[] parameters = str.split(strDelete);
  30.         for (String item : parameters) {
  31.             if (item.startsWith(map.get(Parameters.input))) {
  32.                 if (fileIn == null) {
  33.                     fileIn = item.substring(map.get(Parameters.input).length(), GrammarEqual.length() + 1);
  34.                     fileIn = fileIn.substring(GrammarEqual.length() + 1);
  35.                 }
  36.             }
  37.             if (item.startsWith(map.get(Parameters.num))) {
  38.                 if (stringNum == null) {
  39.                     stringNum = item.substring(map.get(Parameters.num).length(), GrammarEqual.length());
  40.                     stringNum = stringNum.substring(GrammarEqual.length());
  41.                     num = Integer.parseInt(stringNum);
  42.                 }
  43.             }
  44.         }
  45.  
  46.         fin.close();
  47.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement