package codes;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.FilenameFilter;
import java.io.IOException;
import java.security.acl.LastOwnerException;
import java.text.SimpleDateFormat;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
public class ModifyAndDelete
{
private static final String FOLDER_PATH = "C:\\Users\\s13w63\\Desktop\\Zip";
public static void main(String[] args) throws IOException
{
File dir = new File(FOLDER_PATH);
File[] files = dir.listFiles(new FilenameFilter()
{
@Override
public boolean accept(File directory, String fileName)
{
if (fileName.endsWith(".INC"))
{
return true;
}
return false;
}
});
SimpleDateFormat sdf = new SimpleDateFormat("MM");
for(File f:files)
{
String month=sdf.format(f.lastModified());
final int lastModifiedMonth=Integer.parseInt(month);
}
}
}
This is to get the month of the file in which it is modified lastly. Now I want to get the files in a list according to month. How to get the files according to month and I need list for each month. Please help me out guys...
I am using the below code to add and iterate using a hashmap, but It was listing only one file for each month.
Map<Integer, List<File>> map = new HashMap<Integer, List<File>>();
for (File f : files) {
String month = sdf.format(f.lastModified());
final int lastModifiedMonth = Integer.parseInt(month);
map.put(lastModifiedMonth, new ArrayList<File>());
map.get(lastModifiedMonth).add(f);
}
for (Entry<Integer, List<File>> entry : map.entrySet())
{
System.out.println(entry.getKey() + "/" + entry.getValue());
}