開(kāi)源中國(guó),大小軟件,各種編程語(yǔ)言都有,有大項(xiàng)目,也有小例子。
創(chuàng)新互聯(lián)長(zhǎng)期為上千客戶提供的網(wǎng)站建設(shè)服務(wù),團(tuán)隊(duì)從業(yè)經(jīng)驗(yàn)10年,關(guān)注不同地域、不同群體,并針對(duì)不同對(duì)象提供差異化的產(chǎn)品和服務(wù);打造開(kāi)放共贏平臺(tái),與合作伙伴共同營(yíng)造健康的互聯(lián)網(wǎng)生態(tài)環(huán)境。為石柱土家族企業(yè)提供專業(yè)的成都網(wǎng)站制作、成都網(wǎng)站建設(shè)、外貿(mào)營(yíng)銷(xiāo)網(wǎng)站建設(shè),石柱土家族網(wǎng)站改版等技術(shù)服務(wù)。擁有十年豐富建站經(jīng)驗(yàn)和眾多成功案例,為您定制開(kāi)發(fā)。
如果你已經(jīng)安裝了jdk的話,直接找到j(luò)dk的安裝目錄。有2個(gè)文件一個(gè)是jdk1.6(版本號(hào)) 一個(gè)是jre6(Java運(yùn)行環(huán)境) 。進(jìn)入jdk1.6文件夾下,找到src.zip的壓縮文件,解壓就是java se的源代碼
呵呵,,怎么都不去 java的官方網(wǎng)站啊,對(duì)那里不屑一顧么?
自己去看吧,好著呢
去一些IT資源共享網(wǎng)站,如CSDN,51CTO,以及開(kāi)源中國(guó)社區(qū),ing該都是有的!
推薦一個(gè)代碼原創(chuàng)分享網(wǎng)站,也許可以找到一些你需要的代碼
你下載JDK,里面帶src.zip就是源代碼
但這是JAVA類(lèi)庫(kù)代碼,不是虛擬機(jī)代碼
import?java.awt.BorderLayout;
import?java.awt.event.ActionEvent;
import?java.awt.event.ActionListener;
import?java.io.BufferedReader;
import?java.io.IOException;
import?java.io.InputStream;
import?java.io.InputStreamReader;
import?java.net.HttpURLConnection;
import?java.net.MalformedURLException;
import?java.net.URL;
import?java.util.regex.Matcher;
import?java.util.regex.Pattern;
import?javax.swing.JFrame;
import?javax.swing.JLabel;
import?javax.swing.JPanel;
import?javax.swing.JScrollPane;
import?javax.swing.JTextArea;
import?javax.swing.JTextField;
public?class?HttpViewer?extends?JFrame?{
private?JTextField?urlInput;
private?JTextArea?viewArea;
public?static?void?main(String[]?args)?{
new?HttpViewer();
}
public?HttpViewer()?{
this.setTitle("Http?Viewer");
this.setSize(800,?600);
this.setResizable(false);
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
initPanel();
initAction();
this.setVisible(true);
}
//?這個(gè)方法用來(lái)設(shè)置窗口布局
private?void?initPanel()?{
JPanel?northPanel?=?new?JPanel();
JLabel?urlInputLabel?=?new?JLabel("URL:");
urlInput?=?new?JTextField(60);
northPanel.add(urlInputLabel);
northPanel.add(urlInput);
this.add(northPanel,?BorderLayout.NORTH);
JPanel?centerPanel?=?new?JPanel();
viewArea?=?new?JTextArea(27,?60);
centerPanel.add(new?JScrollPane(viewArea));
this.add(centerPanel);
}
//?這個(gè)方法用來(lái)設(shè)置事件
private?void?initAction()?{
urlInput.addActionListener(new?ActionListener()?{
public?void?actionPerformed(ActionEvent?e)?{
String?text?=?urlInput.getText();
if?(text?==?null?||?text.length()?==?0)?{
viewArea.setText("您沒(méi)有輸入U(xiǎn)RL");
return;
}
try?{
URL?url?=?new?URL(text);
String?context?=?getContent(url);
if?(context?!=?null)?{
searchFromText(context);
}
}?catch?(MalformedURLException?e1)?{
viewArea.setText("您輸入的URL不合法:"?+?text);
}
}
});
}
private?String?getContent(URL?url)?{
StringBuffer?builder?=?new?StringBuffer();
int?responseCode?=?-1;
HttpURLConnection?con?=?null;
try?{
con?=?(HttpURLConnection)?url.openConnection();
con.setRequestProperty("User-Agent",
"Mozilla/4.0?(compatible;?MSIE?5.0;?Windows?NT;?DigExt)");//?IE代理進(jìn)行下載
con.setConnectTimeout(60000);
con.setReadTimeout(60000);
//?獲得網(wǎng)頁(yè)返回信息碼
responseCode?=?con.getResponseCode();
if?(responseCode?==?-1)?{
viewArea.setText("連接失敗:"?+?url.toString());
return?null;
}
if?(responseCode?=?400)?{
viewArea.setText("請(qǐng)求失敗,錯(cuò)誤碼:"?+?responseCode);
return?null;
}
InputStream?is?=?con.getInputStream();
InputStreamReader?isr?=?new?InputStreamReader(is);
BufferedReader?br?=?new?BufferedReader(isr);
String?str?=?null;
while?((str?=?br.readLine())?!=?null)
builder.append(str);
is.close();
}?catch?(IOException?e)?{
e.printStackTrace();
viewArea.setText("IOException:?"?+?url.toString());
}?finally?{
con.disconnect();
}
return?builder.toString();
}
private?void?searchFromText(String?context)?{
viewArea.setText("查找URL中:\n");
Pattern?pattern?=?Pattern.compile("a(?[^]+)*(.*?)/a");
Matcher?matcher?=?pattern.matcher(context);
while?(matcher.find())?{
for?(String?prop?:?matcher.group(1).split("?"))?{
int?indexOf?=?prop.indexOf('=');
if?(indexOf??0)?{
if?(prop.substring(0,?indexOf).equals("href"))?{
String?url2?=?prop.substring(indexOf?+?2,?prop.length()?-?1);
viewArea.append(url2?+?"\n");
}
}
}
}
}
}