【发布时间】:2014-10-21 16:12:58
【问题描述】:
我有两个java类,主要是getter和setter等构造函数。
ReportGroup.java
String ReportGroupName;
List<ReportInfo> reportList; //getter & setter
ReportInfo.java
String ReportName;
String ReportId;
String ReportPath; //getter&setter
我已经在 ReportGroup 中设置了 ReportInfo 和 ReportGroupName 中的所有值。是否有任何可能的方法可以将 ReportInfo 的值添加到 ReportGroup 中的列表中(List reportList)
公开课测试{
public static List<ReportInfo> reportInfo = new ArrayList<ReportInfo>();
public static void main(String[] args) throws IOException {
String orgId="346";
String orgName="Ralph Lauren Corporation";
String reportPath= "/"+orgId +"_"+orgName.replaceAll(" ","_");
String reportFolderPath = "C:/Lokesh/Dev Tools/apache-tomcat-6.0.37/webapps/ROOT/Reports";
List<String> filesArray = null;
filesArray = new ArrayList<String>();
String filetowrite="C:/Users/lbandhu/Desktop/test.html";
FileWriter fw=new FileWriter(filetowrite);
ReportGroup reportGroup=new ReportGroup();
reportGroup.setReportGroupName(orgName);
reportGroup.getReportList().addAll(reportInfo);
File folder = new File(reportFolderPath+reportPath);
List<String> reportNames = listFolder(folder);
for (String rname : reportNames) {
ReportInfo reportInfo=new ReportInfo();
reportInfo.setReportName(rname);
folder = new File(reportFolderPath+reportPath+"/"+rname);
System.out.println(folder);
fw.write("<br><tr> "+rname +" Utilization Reports</tr><br>");
Iterator<String> iterator=listFilesForFolder(folder, filesArray).iterator();
writeReportPath( fw,iterator, reportFolderPath,reportInfo);
fw.write("<br>");
}
filesArray.clear();
fw.close();
private static void writeReportPath(FileWriter fw,Iterator<String> iterator, String reportFolderPath,ReportInfo reportInfo) throws IOException
{
while(iterator.hasNext()){
String listofFiles=iterator.next();
StringBuilder strgfile=new StringBuilder(listofFiles);
String filename=strgfile.substring(strgfile.indexOf("/")+1);
//System.out.println("name" +filename);
String[] split = filename.split("_");
if(split.length > 1) {
if(split[0].contains("MONTHLY")) {
//System.out.println(split[1].substring(0, 3) + " " + split[2]);
String monthly=split[1]+ " " + split[2];
int index=monthly.indexOf('/');
String reportId=monthly.substring(0, index);
//ReportInfo reportInfo=new ReportInfo();
//List <ReportInfo> reportGroup=new ArrayList<ReportInfo>();
reportInfo.setReportId(reportId);
reportInfo.setReportPath(reportFolderPath + "/" + strgfile);
fw.write("<br><tr><a href="+"\"" + reportFolderPath + "/" + strgfile+"\""+"/>"
+reportId+"</a></tr>");
}
else {
for(int i = 1; i < split.length; i++) {
//String org=+rname;
String title2=split[i] + " ";
}
//System.out.println("");
}
}
else {
fw.write("<br>"+"<h>"+filename +"</h>"+"<br>");
}
}
}
【问题讨论】:
标签: java spring jakarta-ee jsp-tags