我正在尝试从相当复杂的Java对象生成CSV文件.该对象是具有一些属性的会话,以及具有某些属性的字符串和消息列表以及具有某些属性的注释列表.
会话类如下;
public class Session {
private Long id;
private Date startDate;
private Date endDate;
private List<Message> messages;
private List<String> participants;
public TweetSession() {
}
public TweetSession(Date startDate, List<Message> messages, List<String> participants) {
this.startDate = startDate;
this.messages = messages;
this.participants = participants;
}
public Long getId() {
return id;
}
public Date getStartDate() {
return startDate;
}
public void setStartDate(Date startDate) {
this.startDate = startDate;
}
public Date getEndDate() {
return endDate;
}
public void setEndDate(Date endDate) {
this.endDate = …Run Code Online (Sandbox Code Playgroud) 我正在开发一个程序,需要快速访问CSV逗号分隔的电子表格文件.到目前为止,我已经能够使用BufferedReader轻松读取它.但是,现在我希望能够编辑它读取的数据,然后将其导出回CSV.
电子表格包含姓名,电话号码,电子邮件地址等.该程序列出了每个人的数据,当您点击它们时,它会显示一个包含更多详细信息的页面,也可以从CSV中提取.在该页面上,您可以编辑数据,我希望能够单击"保存更改"按钮,然后将数据导出回CSV中的相应行 - 或删除旧数据,然后附加新数据.
我不太熟悉使用BufferedWriter,或者我应该使用的任何东西.
我开始做的是创建一个名为FileIO的自定义类.它包含BufferedReader和BufferedWriter.到目前为止,它有一个返回bufferedReader.readLine()的方法,名为read().现在我想要一个名为write(String line)的函数.
public static class FileIO {
BufferedReader read;
BufferedWriter write;
public FileIO (String file) throws MalformedURLException, IOException {
read = new BufferedReader(new InputStreamReader (getUrl(file).openStream()));
write = new BufferedWriter (new FileWriter (file));
}
public static URL getUrl (String file) throws IOException {
return //new URL (fileServer + file).openStream()));
FileIO.class.getResource(file);
}
public String read () throws IOException {
return read.readLine();
}
public void write (String line) {
String [] data = line.split("\\|");
String firstName = data[0]; …Run Code Online (Sandbox Code Playgroud) 可能重复:
快速CSV解析
如何正确解析CSV文件到2d数组?
我是java文件处理的新手.请问,任何人都可以告诉我什么是"CSV文件格式",以及如何解析这种类型的文件?
我想从CSV文件中输入员工数据并将其保存在哈希映射中.