【发布时间】:2012-02-01 13:50:35
【问题描述】:
此代码用于下载一个html文件的源代码 但它跳过了一些行,为什么会发生这种情况?
import java.io.IOException;
import java.net.*;
import java.util.*;
import java.io.*;
public class downloadSource {
private URL url;
private URLConnection con;
// Construct the object with a new URL Object resource
downloadSource(String url) {
try {
this.url = new URL(url);
} catch (MalformedURLException e) {
e.printStackTrace();
}
}
// Returns an object instance
public BufferedReader SourceCodeStream() throws IOException {
return new BufferedReader(new InputStreamReader(this.url.openStream()));
}
public void returnSource() throws IOException, InterruptedException {
// FIX ENTRIE SOURCE CODE IS NOT BEING DWLOADED
// Instinate a new object by assigning it the returned object from
// the invoked SourceCodeStream method.
BufferedReader s = this.SourceCodeStream();
if(s.ready()) {
String sourceCodeLine = s.readLine();
Vector<String> linesOfSource = new Vector();
while(sourceCodeLine != null) {
sourceCodeLine = s.readLine();
linesOfSource.add(s.readLine());
}
Iterator lin = linesOfSource.iterator();
while(lin.hasNext()) {
}
}
}
}
【问题讨论】:
标签: java