我有以下代码来检查特定值是否与我服务器上的文本文件中的不同。在 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();
}
提前致谢!