接下来我需要做一个类的工作,我需要读取一个文件并将其存储在对象中,然后用jaxb创建一个xml,我对java和这些文件有点迷茫。txt文件如下:
% 2019-09-21 15:27:14 agonzalez jramirez
La impresora no tiene tóner.
Urgente
% 2019-09-22 10:28:37 jramirez afernandez
No se ha entregado la documentación del expediente EXP324.
Normal
% 2019-09-22 16:28:45 smartinez jramirez
No quedan folios.
Normal
% 2019-09-23 11:03:05 smartinez lsuarez
El ordenador de recepción no funciona.
Urgente
% 2019-09-28 13:11:29 jramirez lsuarez
Mi portátil no puede acceder a la wifi.
Normal
我需要在读取文件时将其存储在下一个对象中:
File file = new File("incidents.txt");
Scanner scanner;
try {
scanner = new Scanner(file);
while (scanner.hasNextLine()) {
String linea = scanner.nextLine();
Scanner delimitar = new Scanner(linea);
delimitar.useDelimiter("\\s*");
Incident i= new Incident();
i.setFechahora(delimitar.next());
i.setOrigen(delimitar.next());
i.setDestino(delimitar.next());
i.setDetalle(delimitar.next());
i.setTipo(delimitar.next());
}
scanner.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
}
稍后我需要用jaxv创建一个xml文件
JAXBContext contexto = JAXBContext.newInstance(Incidencias.class);
Marshaller m = contexto.createMarshaller();
File f = new File("incidencias.xml");
m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
m.marshal(incidencias, f);
我不太懂怎么读,怎么把事件分开。谢谢
暂无答案!
目前还没有任何答案,快来回答吧!