我有以下代码来检查特定值是否与我服务器上的文本文件中的值不同。在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();
}
在此先感谢!
非常感谢!你的答案解决了我的问题。我会接受它,当我可以:) – Erik 2012-04-05 15:53:32