
how to store id and file name in map

Java Storing Id and File Name in Map
import java.io.*;
import java.util.*;
class OnlyExt implements FilenameFilter{
String ext;
public OnlyExt(String ext){
this.ext="." + ext;
}
public boolean accept(File dir,String name){
return name.endsWith(ext);
}
}
class MapExample
{
public static void main(String[] args)
{
FilenameFilter ff = new OnlyExt("txt");
File folder = new File("c:/");
File[] files = folder.listFiles(ff);
Map<Integer,String> map=new HashMap<Integer,String>();
for(int i=0;i<files.length;i++){
int j=i+1;
map.put(j,files[i].getName());
}
Set set = map.entrySet();
Iterator i = set.iterator();
while(i.hasNext()){
Map.Entry me = (Map.Entry)i.next();
System.out.println(me.getKey() + " \t:\t " + me.getValue());
}
}
}

hey many thanks.....
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.