0

So I made this piece of code:

options = getURL("http://florens.be/EnterRoomAlert/options.txt");
soundOptionStartPos = options.indexOf("sound") + 6;
soundOptionEndPos = options.indexOf("e", soundOptionStartPos) + 1;
soundOptionResult = options.substring(soundOptionStartPos, soundOptionEndPos);

And this is the getURL method:

public static String getURL(String urlToRead) throws Exception {
  StringBuilder result = new StringBuilder();
  URL url = new URL(urlToRead);
  HttpURLConnection conn = (HttpURLConnection) url.openConnection();
  conn.setRequestMethod("GET");
  BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
  String line;
  while ((line = rd.readLine()) != null) {
     result.append(line);
  }
  rd.close();
  return result.toString();
}

This is the content off the file options.txt:

sound=false
mail=false
database=false

Everytime I run this code and print out soundOptionResult I get true.

Florens
  • 91
  • 12
  • Have you debugged your code? This is a good learning opportunity to learn how to set breakpoints and step through the code to figure out what it's actually doing. – mvd Nov 02 '15 at 17:53
  • Probably not the actual contents of the file. – Kayaman Nov 02 '15 at 17:55
  • Are you saying that if you fetch the file with for example `wget`, the contents will be false? But your code magically turns it to true? And have you checked that you're actually reading the right URL in your code? – Kayaman Nov 02 '15 at 17:56
  • Does it work with `public static String getURL(String urlToRead) throws Exception { return "sound=false\nmail=false\ndatabase=false"; }` ? – assylias Nov 02 '15 at 18:04

0 Answers0