我嘗試閱讀從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/看到這個網頁。 –