pek*_*pek 35
我目前正在使用这个:
String content = null;
URLConnection connection = null;
try {
connection = new URL("http://www.google.com").openConnection();
Scanner scanner = new Scanner(connection.getInputStream());
scanner.useDelimiter("\\Z");
content = scanner.next();
scanner.close();
}catch ( Exception ex ) {
ex.printStackTrace();
}
System.out.println(content);
Run Code Online (Sandbox Code Playgroud)
但不确定是否有更好的方法.
Sco*_*ish 21
这对我很有用:
URL url = new URL(theURL);
InputStream is = url.openStream();
int ptr = 0;
StringBuffer buffer = new StringBuffer();
while ((ptr = is.read()) != -1) {
buffer.append((char)ptr);
}
Run Code Online (Sandbox Code Playgroud)
不确定提供的其他解决方案是否更有效.
| 归档时间: |
|
| 查看次数: |
55025 次 |
| 最近记录: |