2011-06-26 61 views
0

我已经开发了在水库AA XML文件的应用程序/ XML文件夹与Android的web服务器XML

是在那里在XML文件中的信息同步处理本地XML被认为是静态的,但我们有一个现在在需要的XML文件中的新要求,通过Web服务器

什么是可能的方式出局

  1. 什么是阅读从Android的Web服务器的XML文件的最好的方式进行更新?示例代码将有帮助
  2. 一旦从Web服务器读取了XML,我可以在手机上修改XML吗?
  3. 还有其他的可能吗?

感谢

回答

0

您将需要使用的URLConnection下载:

public void DownloadFromUrl(String imageURL, String fileName) { //this is the downloader method 
     try { 
       URL url = new URL("http://yoursite.com/" + imageURL); //you can write here any link 
       File file = new File(fileName); 

       long startTime = System.currentTimeMillis(); 
       Log.d("ImageManager", "download begining"); 
       Log.d("ImageManager", "download url:" + url); 
       Log.d("ImageManager", "downloaded file name:" + fileName); 
       /* Open a connection to that URL. */ 
       URLConnection ucon = url.openConnection(); 

       /* 
       * Define InputStreams to read from the URLConnection. 
       */ 
       InputStream is = ucon.getInputStream(); 
       BufferedInputStream bis = new BufferedInputStream(is); 

       /* 
       * Read bytes to the Buffer until there is nothing more to read(-1). 
       */ 
       ByteArrayBuffer baf = new ByteArrayBuffer(50); 
       int current = 0; 
       while ((current = bis.read()) != -1) { 
         baf.append((byte) current); 
       } 

       /* Convert the Bytes read to a String. */ 
       FileOutputStream fos = new FileOutputStream(file); 
       fos.write(baf.toByteArray()); 
       fos.close(); 
       Log.d("ImageManager", "download ready in" 
           + ((System.currentTimeMillis() - startTime)/1000) 
           + " sec"); 

     } catch (IOException e) { 
       Log.d("ImageManager", "Error: " + e); 
     } 

} 

http://www.helloandroid.com/tutorials/how-download-fileimage-url-your-device

IBM对此有一定的帮助,基本上该文件将被保存到一个InputStream ,您可以从那里使用它或将其保存到文件中。

http://www.ibm.com/developerworks/opensource/library/x-android/