特定の値がサーバー上のテキスト ファイルと同じでないかどうかを確認する次のコードがあります。PHP では非常に単純です$str = '1.3'; if($str != '1.2') { die('not the same!'); }
。Java では...そうですね。私は本当に知りません。それは私があなたに尋ねているからです。それはどうあるべきですか?
try {
// Create a URL for the desired page
URL url = new URL("http://erik-edgren.nu/weather-right-now.txt");
// Read all the text returned by the server
BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
String str;
while ((str = in.readLine()) != null) {
if(str != "1.2") {
Toast.makeText(this, "Ny version finns att hämta: v" + str, Toast.LENGTH_SHORT).show();
}
}
in.close();
} catch (MalformedURLException e) {
Toast.makeText(this, "error 1", Toast.LENGTH_SHORT).show();
} catch (IOException e) {
Toast.makeText(this, "error 2", Toast.LENGTH_SHORT).show();
}
前もって感謝します!