我在Bean中使用以下Java代码来读取URL的内容:
String url;
String inputLine;
StringBuilder srcCode=new StringBuilder();
public void setUrl (String value) {
url = value;
}
private void scanWebPage() throws IOException {
try {
URL dest = new URL(url);
URLConnection yc = dest.openConnection();
yc.setUseCaches(false);
BufferedReader in = new BufferedReader(new
InputStreamReader(yc.getInputStream()));
while ((inputLine = in.readLine()) != null)
srcCode = srcCode.append (inputLine);
in.close();
} catch (FileNotFoundException fne) {
srcCode.append("File Not Found") ;
}
}
Run Code Online (Sandbox Code Playgroud)
该代码适用于大多数URL,但不适用于重定向的URL.如何更新上述代码以从重定向的URL中读取内容?对于重定向的网址,我知道"File Not Found".
java ×1