0
我開發了一些代碼,可以訪問url並從中讀取流,但是當我試圖獲取流時,我得到了java.net。 SocketException。這裏是堆棧跟蹤:java.net.SocketException:從流中讀取時重置連接
java.net.SocketException: Connection reset
at java.net.SocketInputStream.read(SocketInputStream.java:168)
at java.io.BufferedInputStream.fill(BufferedInputStream.java:218)
at java.io.BufferedInputStream.read1(BufferedInputStream.java:258)
at java.io.BufferedInputStream.read(BufferedInputStream.java:317)
at sun.net.www.http.HttpClient.parseHTTPHeader(HttpClient.java:687)
at sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:632)
at sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:652)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1049)
at utils.AljazemArabicWordsGrabber.grab(AljazemArabicWordsGrabber.java:46)
at utils.TranslatorThread.run(TranslatorThread.java:39)
,這裏是導致異常的代碼:
public String[] grab(EnglishWord englishWord) {
try {
aljazemURL = new URL(urlLink + englishWord.getLemma());
connection = aljazemURL.openConnection();
//connection.connect();
// System.out.println("connection:" + connection);
//// stream = connection.getInputStream();
// reader = new InputStreamReader(stream);
in = new BufferedReader(new InputStreamReader(connection.getInputStream())); // the exception occurs here..
while ((decodedString = in.readLine()) != null) {
if (decodedString.contains("<div class=\"default_to_trans_ar\" style=\"display:block\">")) {
decodedString = decodedString.replace("<div class=\"default_to_trans_ar\" style=\"display:block\">", "");
decodedString = decodedString.replace("</div>", "");
slicedWords = decodedString.split(",");
for (String slice : slicedWords) {
System.out.println(slice);
}
// System.out.println(decodedString);
}
}
in.close();
} catch (Exception e) {
e.printStackTrace();
}
return slicedWords;
}
您可能要檢查這一個:http://stackoverflow.com/questions/62929/java-net-socketexception-connection-reset – Sujay 2012-07-12 00:21:29
我檢查了這一個,之後我發佈我的問題,它實際上並沒有幫助 – Khafaga 2012-07-12 01:20:54
'實際上沒有幫助'?它列出了所有三種可能的原因。 – EJP 2012-07-12 02:11:39