?? stockreader.java
字號(hào):
package ch07.section10;
import java.io.*;
import java.net.*;
public class StockReader {
public static void main(String argv[]) throws Exception {
String urlString = "http://quote.yahoo.com/d/quotes.csv?";
String p = "s=SUNW&f=slc1wop";
try {
//創(chuàng)建URL實(shí)例
URL url = new URL(urlString);
//打開(kāi)URL連接并得到URLConnectiong實(shí)例
URLConnection connection = url.openConnection();
//設(shè)置可以輸出
connection.setDoOutput(true);
PrintWriter out = new PrintWriter(connection.getOutputStream());
out.println(p);
out.close();
//得到服務(wù)器返回的消息
BufferedReader in = new BufferedReader(
new InputStreamReader(connection.getInputStream()));
String line = in.readLine();
in.close();
//將結(jié)果輸出到信息欄
System.out.println("Name: " + Stock.getName(line));
System.out.println("Price: " + Stock.getPrice(line));
System.out.println("Date: " + Stock.getDate(line));
}
catch (MalformedURLException e) {
System.out.println(e.getMessage());
}
catch (IOException e) {
System.out.println(e.toString());
}
}
}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -