xml文件如下:
package com.pdsu.file.xml; import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.InputStream; import java.util.ArrayList; import java.util.List; import org.junit.Test; import android.test.AndroidTestCase; import com.pdsu.file.xml.Person; import com.pdsu.file.xml.PersonXML; public class PersonXMLTest extends AndroidTestCase{ @Test public void testReadXML() throws Exception{ InputStream is = this.getClass().getClassLoader().getResourceAsStream("person.xml"); PersonXML personXml = new PersonXML(); List<Person> persons = personXml.readXML(is); for(Person person :persons){ System.out.println(person); } } @Test public void save() throws Exception{ List<Person> persons = new ArrayList<Person>(); persons.add(new Person(1,"name1",11)); persons.add(new Person(2,"name2",112)); persons.add(new Person(3,"name3",113)); persons.add(new Person(4,"name4",114)); PersonXML personXml = new PersonXML(); FileOutputStream fos = new FileOutputStream(getContext().getFilesDir()+File.separator+"person.xml"); personXml.saveXML(persons, fos); } }