【发布时间】:2026-01-31 21:25:01
【问题描述】:
我正在处理一个项目,该程序应该分析其他项目,其他项目位于特定目录中。这些项目的命名标准类似于以下:
项目名称-版本-下载日期示例:
ElasticSearch-1.0-20160417
现在程序可以使用以下方法将整个项目名称作为一个字符串返回并保存到 CSV 文件中:
private String projectName;
public void setProjectName(String projectName){
this.projectName = projectName;
}
public String getProjectName(){
return projectName;
}
这里是写项目名称的方法调用:
private void writeReport() {
BufferedWriter out = null;
try {
File file = new File("out.csv");
boolean exists = file.exists();
FileWriter fstream = new FileWriter(file, exists /*=append*/);
out = new BufferedWriter(fstream);
if (!exists) {
out.write("File Name;");
out.write(System.getProperty("line.separator"));
}
out.write(String.valueOf(newFiles.getProjectName()) + ";"); //method call
out.write(System.getProperty("line.separator"));
// }
//Close the output stream
out.close();
} catch (Exception e) {
System.err.println("Error: " + e.getMessage());
// return;
}
}
现在我的问题是如何将项目名称拆分为三个部分并将每个部分分别写入 CSV 文件中?
项目名称、版本和下载日期?这意味着它应该从位于第一个“-”之前的子字符串和第一个“-”之后的版本中获取项目名称,最后是第二个“-”之后的日期?
任何提示如何做到这一点?
谢谢
【问题讨论】: