$ cat ReadAndOutputFile.java
//ReadAndOutputFile.java
//
import java.util.List;
import java.util.ArrayList;
import java.util.Date;
import java.util.Calendar;
import java.io.File;
import java.text.ParseException;
import java.text.SimpleDateFormat;
public class ReadAndOutputFile{
private static List createDateList(String datestr, int nday) throws Exception{
Calendar cal = Calendar.getInstance();
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
Date date = sdf.parse(datestr);
cal.setTime(date);
List dateList = new ArrayList ();
for(int i=0;i
dateList.add(sdf.format(cal.getTime()));
cal.add(Calendar.DATE,-1);
}
return dateList;
}
private static String getToday(){
Calendar cal = Calendar.getInstance();
SimpleDateFormat sdf = new SimpleDateFormat ("yyyyMMdd");
String today = sdf.format(cal.getTime());
return today;
}
public static void main(String[] args) throws Exception{
//List dateList = createDateList("20151207",7);
String dat;
int n;
if(args.length==0){
dat = getToday();
n = 7;
}
else if(args.length==1){
dat = args[0];
n = 7;
}
else{
dat = args[0];
n = Integer.parseInt(args[1]);
}
System.out.println(dat+"\t"+n);
List dateList = createDateList(dat,n);
for(String x: dateList)
System.out.print(x+",");
System.out.println();
}
}