问题解决,谢谢各位
我在Tomcat中建立了一个文件,想在Eclipse中实现从该文件中下载其中的XML文件。
这个下载类:
public class HttpDownloader {
private URL url = null;
public String Download(String urlStr)
{
StringBuffer sb= new StringBuffer();
String line = null;
BufferedReader buffer = null;
try {
url = new URL(urlStr);
HttpURLConnection urlConn = (HttpURLConnection)url.openConnection();
buffer = new BufferedReader(new InputStreamReader(urlConn.getInputStream()));
while((line = buffer.readLine()) != null)
{
sb.append(line);
}
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}finally{
try {
buffer.close();
} catch (Exception e2) {
// TODO: handle exception
e2.printStackTrace();
}
}
return sb.toString();
}
}
这是在Activity中编写的下载函数:
private String downloadXML(String urlStr)
{
HttpDownloader httpDownloader = new HttpDownloader();
String result = httpDownloader.Download(urlStr);
return result;
}
调用方式是:
String xml = downloadXML("http://localhost:8080/mp3/resources.xml");
Log.d("TAG", "xml-->" + xml);
问题是一直都下载不下来。
小妹才开始学,请大牛们帮忙解答一下,谢谢。