Android从服务上下载文件
首先在电脑上配置tomcat,webapps目录下新建mp3文件夹,
截图
首先我们通过SAX解析resources.xml 获取歌曲信息。
启动 Tomcat访问一下服务器地址http://210.**.**.**:8080/mp3/resources.xml
210.**.**.**是我的IP,把这里改成自己的IP
本来下载是一个耗时的东西,需要另外开启一个线程或则service去下载,由于这里就在本人的电脑上测试
就在主线程中下载了
Info.java
package rw.down;
public class Info {
int id;
String nameString;
/**
* @return the id
*/
public int getId() {
return id;
}
/**
* @param id the id to set
*/
public void setId(int id) {
this.id = id;
}
/**
* @return the nameString
*/
public String getNameString() {
return nameString;
}
/**
* @param nameString the nameString to set
*/
public void setNameString(String nameString) {
String = nameString;
}
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
@Override
public String toString() {
return "info [id=" + id + ", nameString=" + nameString + "]";
}
}
infoHandle.java
package rw.down;
import java.util.List;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;
import Android.util.Log;
public class infoHandle extends DefaultHandler {
private Info Mp3_info;
private List List_Mp3_Infos;
private String preString;
public infoHandle() {
super();
}
public infoHandle(List list_Mp3_Infos) {
super();
List_Mp3_Infos = list_Mp3_Infos;
}
@Override
public void startDocument() throws SAXException {
// TODO Auto-generated method stub
super.startDocument();
}
@Override
public void startElement(String uri, String localName, String qName,
Attributes attributes) throws SAXException {
// TODO Auto-generated method stub
preString=localName;
if (preString.equals("resource")) {
Mp3_info=new Info();
}
super.startElement(uri, lo