package test;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Random;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
public class CreatEpg {
public static epg Xml(File file){
epg epg = new epg();
//设置当前时间
epg.setCreatedTime(getDate());
epg.setVersion("1.0");
epg.setChannelCode("0"+file.getName().substring(file.getName().indexOf(".")-1, file.getName().indexOf(".")) + "25");
epg.setChannelName(file.getName().substring(file.getName().indexOf("_")+1,file.getName().indexOf(".")));
epg.setTerminalType("stb,mobile");
epg.setDefinitionType("SD");
epg.setBusiType("");
//info 数据
info info = new info("","中国大陆","","普通话","","0.0","综合,对话,热点");
List<Program> programList = new ArrayList<Program>();
try {
FileReader fileReader = new FileReader(file);
BufferedReader bufferedReader = new BufferedReader(fileReader);
String tempLine = "";
int line = 0;
while((tempLine = bufferedReader.readLine()) != null){
line ++ ;
//处理文件
Program program = new Program();
String[] lineContent = tempLine.split(
",(?=([^\"]*\"[^\"]*\")*[^\"]*$)", -1);// 按逗号分开
program.setEndTime(lineContent[2]);
program.setStartTime(lineContent[1]);
name name = new name("chi",lineContent[0]);
program.setName(name);
String random = "";
for(int i = 0; i<3;i++){
Integer integer = new Random().nextInt(10);
random+=String.valueOf(integer);
}
String assertId = "mcap" + epg.getChannelCode() + random;
program.setAssetId(assertId);
program.setInfo(info);
program.setReserve("0");
program.setPosterList("");
program.setDescription("");
programList.add(program);
}
System.out.println(line);
epg.setProgramList(programList);
bufferedReader.close();
fileReader.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return epg;
}
public static void main(String[] args) {
try {
// File file1 = new File("F://output_cctv1.txt");
// File file2 = new File("F://output_cctv2.txt");
// File file3 = new File("F://output_cctv3.txt");
// File file4 = new File("F://output_cctv4.txt");
File file5 = new File("F://output_cctv5.txt");
File file6 = new File("F://output_cctv6.txt");
List<File> files = new ArrayList<File>();
// files.add(file6);files.add(file5);files.add(file4);files.add(file3);files.add(file2);files.add(file1);
files.add(file5);files.add(file6);
JAXBContext context = JAXBContext.newInstance(epg.class);
// 下面代码演示将对象转变为xml
Marshaller m = context.createMarshaller();
m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); //设置XML自动换行
for(File file : files){
epg epg = CreatEpg.Xml(file);
//要存储的文件路径
File target_file = new File ("F:\\test\\");
if(!target_file.exists()){
target_file.mkdirs();
}
FileWriter fw = new FileWriter(target_file.getAbsolutePath()+"\\"+file.getName().substring(file.getName().indexOf("_")+1,file.getName().indexOf("."))+".xml");
m.marshal(epg, fw);
fw.close();
}
} catch (JAXBException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
/**
* 获取当前时间
* */
public static String getDate(){
Date date = new Date();
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
return dateFormat.format(date);
}
}
package test;
import java.util.List;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlElementWrapper;
import javax.xml.bind.annotation.XmlRootElement;
@XmlRootElement
public class epg {
private String createdTime;
private String version;
private String channelCode;
private String channelName;
private String terminalType;
private String definitionType;
private String busiType;
private List<Program> programList;
public epg() {
super();
// TODO Auto-generated constructor stub
}
public epg(String createdTime, String version, String channelCode,
String channelName, String terminalType, String definitionType,
String busiType, List<Program> programList) {
super();
this.createdTime = createdTime;
this.version = version;
this.channelCode = channelCode;
this.channelName = channelName;
this.terminalType = terminalType;
this.definitionType = definitionType;
this.busiType = busiType;
this.programList = programList;
}
@XmlAttribute
public String getCreatedTime() {
return createdTime;
}
public void setCreatedTime(String createdTime) {
this.createdTime = createdTime;
}
@XmlAttribute
public String getVersion() {
return version;
}
public void setVersion(String version) {
this.version = version;
}
@XmlElement
public String getChannelCode() {
return channelCode;
}
public void setChannelCode(String channelCode) {
this.channelCode = channelCode;
}
@XmlElement
public String getChannelName() {
return channelName;
}
public void setChannelName(String channelName) {
this.channelName = channelName;
}
@XmlElement
public String getTerminalType() {
return terminalType;
}
public void setTerminalType(String terminalType) {
this.terminalType = terminalType;
}
@XmlElement
public String getDefinitionType() {
return definitionType;
}
public void setDefinitionType(String definitionType) {
this.definitionType = definitionType;
}
@XmlElement
public String getBusiType() {
return busiType;
}
public void setBusiType(String busiType) {
this.busiType = busiType;
}
@XmlElementWrapper
@XmlElement(name="program")
public List<Program> getProgramList() {
return programList;
}
public void setProgramList(List<Program> programList) {
this.programList = programList;
}
}
package test;
import javax.xml.bind.annotation.XmlAttribute;
public class info {
private String actors;
private String area;
private String director;
private String language;
private String playdate;
private String score;
private String type;
public info(String actors, String area, String director, String language,
String playdate, String score, String type) {
super();
this.actors = actors;
this.area = area;
this.director = director;
this.language = language;
this.playdate = playdate;
this.score = score;
this.type = type;
}
public info() {
super();
// TODO Auto-generated constructor stub
}
@XmlAttribute
public String getActors() {
return actors;
}
public void setActors(String actors) {
this.actors = actors;
}
@XmlAttribute
public String getArea() {
return area;
}
public void setArea(String area) {
this.area = area;
}
@XmlAttribute
public String getDirector() {
return director;
}
public void setDirector(String director) {
this.director = director;
}
@XmlAttribute
public String getLanguage() {
return language;
}
public void setLanguage(String language) {
this.language = language;
}
@XmlAttribute
public String getPlaydate() {
return playdate;
}
public void setPlaydate(String playdate) {
this.playdate = playdate;
}
@XmlAttribute
public String getScore() {
return score;
}
public void setScore(String score) {
this.score = score;
}
@XmlAttribute
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
}
package test;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlValue;
public class name {
private String language;
private String aaa;
@XmlAttribute
public String getLanguage() {
return language;
}
public void setLanguage(String language) {
this.language = language;
}
@XmlValue
public String getAaa() {
return aaa;
}
public void setAaa(String aaa) {
this.aaa = aaa;
}
public name() {
super();
}
public name(String language,String aa) {
super();
this.language = language;
this.aaa=aa;
}
}
相关推荐
目标检测中CSV格式转XML格式
目前只支持CSV转换到XM或者JSON,如果需要其他的转换工具可以找我,或者等我后续在补上,输出输入格式可选,支持选择定位的文件,和保存的文件夹
java实现csv 转 xml,内含3种 方法
csv数据标注格式转xml文件格式,便于SSD和YOLO训练 详见:https://blog.csdn.net/Mynameisyournamewuyu/article/details/81124692
此程序是用vs2017编写,将里面的csv文件转成xml文件,xml文件输出在D盘,输出的xml文件格式可以自己改
将xml文件转换成csv格式,好资源,好分享
CSV 到 XML 转换器这是一个用 Java 为 FOSSASIA 编写的 CSV 到 XML 转换器。如何使用它下载存储库并在同一文件夹中解压缩。 打开并编辑csvxmlconverter.bat并更改您自己目录的文件路径。 java -jar csvxmlconverter....
将editor目录放入unity工程assets目录下,在菜单栏可见到plugins。选中unity里面一个excel文件.xlsx文件,点击plugins的exceltools,选择转换后格式默认输出到excel同路径的文件
表格转csv-xml-json
xml2csv 这是一个命令行实用程序和库,可根据用户提供的配置将XML文件转换为CSV文件。 为什么要使用xml2csv? xml2csv适用于以下情况: 您有一组XML文件: 所有都需要转换。 其中一些需要根据文件名进行转换。 ...
一个将CSV转换为Xml和Json的小程序。 在项目中,我添加了两个示例csv文件。 一个是纯csv,另一个是具有csv结构的txt文件。 正如我在帮助部分中所写的那样,所有文件都必须具有标头。 使用正则表达式对行进行分割,...
XML 转换 CSV文件,可打开查看对比xml文件
xml2csv 一个xml文件转化为csv的小工具
python-csv-to-xml 将CSV文件转换为XML的Python脚本
一个简单但功能强大的 Java 实用程序,用于将 CSV 转换为 XML 格式。 用 NetBeans 编写。 我不会以任何方式监控或维护此代码; 所以使用风险自负。 欢迎您 fork 这个项目,但请告诉我,以便我可以更新链接并将人们引...
专业批量XML转CSV,好用好东西大家分享。一键拖拽,很好用。
一个为Unity3D编写的插件,可以快速地将Excel文件转换为JSON、CSV和XML,方便在游戏过程中处理各种Excel文件
这是之前Excel转json工具的升级版,增加了转换xml和csv的功能。同时优化了转换速度和数字的存储,特别是科学计数法的数字,现在不会出现一长串数字的情况了。如果需要对某些大数字保留原样转换输出,请设置单元格...
将openiamges_v4中带标注框的csv文件,转换成voc格式,转换结果:xml文件,图片
软件介绍: 本程序能够直接将XML文件拖放到软件窗口中即可转换,使用非常方便,简单的一键拖拽,很好用。