我必须将 XML 写入我的 SD 卡,因为我想获取 input-Stream 但要确定这一点,当我从 android 调用任何方法时如何获取 URL?
例如,当我从android调用该方法时,我想下载包含10,000条记录的所有登录详细信息,但是如何获取URL以便我可以建立连接并获取输入流以写入文件...请在下面帮助我是我的代码
public void DownloadFiles(){
try {
URL url = new URL("http://192.168.0.10/INIFARM/fieldbook/webservice1.asmx?wsdl");
URLConnection conexion = url.openConnection();
conexion.connect();
int lenghtOfFile = conexion.getContentLength();
InputStream is = url.openStream();
File testDirectory = new File("/data/data/com.example.androidwebservice/");
if (!testDirectory.exists()) {
testDirectory.mkdir();
}
FileOutputStream fos = new FileOutputStream(testDirectory + "/response.xml");
byte data[] = new byte[1024];
int count = 0;
long total = 0;
int progress = 0;
while ((count = is.read(data)) != -1) {
total += count;
int progress_temp = (int) total * 100 / lenghtOfFile;
if (progress_temp % 10 == 0 && progress != progress_temp) {
progress = progress_temp;
}
fos.write(data, 0, count);
}
is.close();
fos.close();
Log.v(TAG, "File is Downloaded Successfully");
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}