public static void getClientUpdate() {
try {
String inputLine;
double version = 0;
URL url = new URL("http://ds-forums.com/client/version.txt");
BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
while ((inputLine = in.readLine()) != null)
System.out.println(inputLine);
in.close();
version = inputLine;
System.out.println("The version is: " + version);
} catch (Exception x) {
System.out.println(x);
}
}
這聽起來很愚蠢,但我有一個包含雙精度型的文本文件,我想將它保存爲雙精度型。相反,它需要一個字符串。我做錯了嗎?還是僅僅需要添加幾個步驟?從URL讀取,將數據存儲爲double?
想知道爲什麼他不能用一個DataInputStream裝飾url.openStream()並使用readDouble()? – 2011-01-18 22:27:43