此方法返回给定 URL 的来源。
private static String getUrlSource(String url) {
try {
URL localUrl = null;
localUrl = new URL(url);
URLConnection conn = localUrl.openConnection();
BufferedReader reader = new BufferedReader(
new InputStreamReader(conn.getInputStream()));
String line = "";
String html;
StringBuilder ma = new StringBuilder();
while ((line = reader.readLine()) != null) {
ma.append(line);
}
return ma;
} catch (Exception e) {
Log.e("ERR",e.getMessage());
}
}
它给了我这个错误:
Type mismatch: cannot convert from StringBuilder to String
还有两个选择:
Change the return type to StringBuilder.
但我希望它返回一个字符串。Change type of ma to String.
更改 String 后没有 append() 方法。