GET和子串的奇怪行为

时间:2015-11-02 17:51:05

标签: java http get substring indexof

所以我做了这段代码:

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

这是getURL方法:

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();
}

这是文件options.txt的内容:

sound=false
mail=false
database=false

每次我运行此代码并打印soundOptionResult时,我都会true

0 个答案:

没有答案