我尝试阅读从PHP代码生成的xml字符串的web内容。这里的result。但它保持我的应用程序崩溃。当t尝试阅读www.yahoo.com时也是如此。Android:读取xml字符串的网页内容
这里是我的代码
public static void downloadString(String urlString,String saveLoc, String fileName){
URL url;
try {
url = new URL(urlString);
//URLConnection conn = url.openConnection();
HttpURLConnection conn = (HttpURLConnection)url.openConnection();
int code = conn.getResponseCode();
BufferedReader br = new BufferedReader(
new InputStreamReader(conn.getInputStream()));
String inputLine;
String fullFileName = saveLoc + "//" + fileName;
File file = new File(fullFileName);
if (!file.exists()) file.createNewFile();
FileWriter fw = new FileWriter(file.getAbsoluteFile());
BufferedWriter bw = new BufferedWriter(fw);
while ((inputLine = br.readLine()) != null) {bw.write(inputLine);}
bw.close();
br.close();
} catch (IOException e) {
e.printStackTrace();
}
}
我尝试调试和不能从
INT码= conn.getResponseCode通过();
我不知道什么确切的错误。请指教。谢谢。
对不起,我真的不知道这个......如何使用这段代码? –
https://www.simplifiedcoding.net/wordpress-to-android-app-tutorial/看到这个网页。 –