Ejemplo n.º 1
0
 /**
  * This assumes each line is of the form (number=value) and it adds each value in order of the
  * lines in the file
  *
  * @param file Which file to load
  * @return An index built out of the lines in the file
  */
 public static Index<String> loadFromFilename(String file) {
   Index<String> index = new HashIndex<String>();
   BufferedReader br = null;
   try {
     br = new BufferedReader(new FileReader(file));
     for (String line; (line = br.readLine()) != null; ) {
       int start = line.indexOf('=');
       if (start == -1 || start == line.length() - 1) {
         continue;
       }
       index.add(line.substring(start + 1));
     }
     br.close();
   } catch (Exception e) {
     e.printStackTrace();
   } finally {
     if (br != null) {
       try {
         br.close();
       } catch (IOException ioe) {
         // forget it
       }
     }
   }
   return index;
 }
Ejemplo n.º 2
0
 /**
  * This assumes each line is one value and creates index by adding values in the order of the
  * lines in the file
  *
  * @param file Which file to load
  * @return An index built out of the lines in the file
  */
 public static Index<String> loadFromFileWithList(String file) {
   Index<String> index = new HashIndex<String>();
   BufferedReader br = null;
   try {
     br = new BufferedReader(new FileReader(file));
     for (String line; (line = br.readLine()) != null; ) {
       index.add(line.trim());
     }
     br.close();
   } catch (Exception e) {
     e.printStackTrace();
   } finally {
     if (br != null) {
       try {
         br.close();
       } catch (IOException ioe) {
         // forget it
       }
     }
   }
   return index;
 }