title: Java: Reading file line by line
body: <p>Okay, I am a newbie java programmer, and am trying to create some java code to read a configuration file that I have created, and return the results. I will give you the code first, then explain what I am trying to do:</p>
  
  <pre><code>public static String read(String property, File file) throws IOException{
  
      FileInputStream in = new FileInputStream(file);
      BufferedReader br = new BufferedReader(new InputStreamReader(in));
      String line;
      String r = "ERROR";
      while ((line = br.readLine()) != null) {
          if(!line.startsWith("//")){
              String[] split = line.split(" ");
              if(split[0] == property){
                  r = split[1];
              }
          }
      }
  
      br.close();
  
      return r;
  
  }
  </code></pre>
  
  <p>This is what the actual configuration file looks like, where "hello" is the property, and "world" is the value:</p>
  
  <pre><code>hello world
  </code></pre>
  
  <p>To explain, the  desired property is taken as a parameter, as well as the location of theconfiguration file.  It will then read each line (ignoring "//") and split it into the property name and value. It will then return the value if it was found, or "ERROR" if the property could not be found.</p>
  
  <p>I then run the following code:</p>
  
  <pre><code>System.out.println(Property.read("hello", new File("config/confix.txt")));
  </code></pre>
  
  <p>However, <strong>every</strong> time I run this code, "ERROR" will be printed. I have checked and re-checked my code, and still can't think of what I have done wrong.</p>
  
  <p>Apologies if I have not made myself very clear, so do ask if I need to explain better!</p>