<dependency> <groupId>org.beanio</groupId> <artifactId>beanio</artifactId> <version>2.0.7</version> </dependency> <beanio xmlns="http://www.beanio.org/2016/01" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.beanio.org/2016/01 http://www.beanio.org/2016/01/mapping.xsd"> <stream name="students" format="csv"> <record name="student" class="com.example.Student"> <field name="name" /> <field name="age" type="int" /> </record> </stream> </beanio> public class Student { private String name; private int age; // Getter and setter methods // ... } public class DataConversionExample { public static void main(String[] args) { StreamFactory factory = StreamFactory.newInstance(); factory.load("studentMapping.xml"); Reader reader = factory.createReader("students", new File("students.csv")); Object record; while ((record = reader.read()) != null) { if ("student".equals(reader.getRecordName())) { Student student = (Student) record; System.out.println("Name: " + student.getName()); System.out.println("Age: " + student.getAge()); } } reader.close(); } }


上一篇:
下一篇:
切换中文