Advertisement
Luciano_fuentes

Untitled

Oct 27th, 2017
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.20 KB | None | 0 0
  1. public static int getIndexVar(String path, String main, String var){
  2.         String line;
  3.         int bytesVarIndex = 0;
  4.         int bytesVarIndexMain = 0;
  5.  
  6.         try {
  7.             BufferedReader br = new BufferedReader(new FileReader(path));
  8.             while (!isNull(line = br.readLine())){
  9.                     bytesVarIndex++;
  10.                 if ("[".equalsIgnoreCase(String.valueOf(line.charAt(0))) && "]".equalsIgnoreCase(String.valueOf(line.charAt((line.length()) - 1)))){
  11.                     if (main.equalsIgnoreCase(line)){
  12.                         while(!isNull(line = br.readLine())){
  13.                             ++bytesVarIndexMain;
  14.                             if(var.equalsIgnoreCase(line.substring(0, line.indexOf("=")))){
  15.                                 br.close();
  16.                                 return (bytesVarIndex + bytesVarIndexMain);
  17.                             }
  18.                         }
  19.                     }
  20.                 }
  21.             }
  22.         } catch (FileNotFoundException ex) {
  23.             System.out.println(ex.getMessage());
  24.         } catch (IOException ex) {
  25.             System.out.println(ex.getMessage());
  26.         }
  27.         return -1; // (-1 = ERROR!);
  28.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement