title: Read the each string text from file in java
body: <p>I am new in java. I just wants to read each string in java and print it on console.</p>
  
  <p>Code:</p>
  
  <pre><code>public static void main(String[] args) throws Exception {
  
      File file = new File("/Users/OntologyFile.txt");
      try {
          FileInputStream fstream = new FileInputStream(file);
          BufferedReader infile = new BufferedReader(new InputStreamReader(
                  fstream));
          String data = new String();
          while ((data = infile.readLine()) != null) { // use if for reading just 1 line
              System.out.println(""+data);
          }
      } catch (IOException e) {
          // Error
      }
  }
  </code></pre>
  
  <p>If file contains:</p>
  
  <pre><code>Add label abc to xyz
  Add instance cdd to pqr
  </code></pre>
  
  <p>I want to read each word from file and print it to a new line, e.g.</p>
  
  <pre><code>Add
  label
  abc
  ...
  </code></pre>
  
  <p>And afterwards, I want to extract the index of a specific string, for instance get the index of <code>abc</code>.</p>
  
  <p>Can anyone please help me?</p>