Stoting file name in Map

Stoting file name in Map

how to store id and file name in map

View Answers

February 16, 2011 at 3:14 PM

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());
    }
    }
}

February 16, 2011 at 3:38 PM

hey many thanks.....









Related Tutorials/Questions & Answers:
Stoting file name in Map
Stoting file name in Map  how to store id and file name in map
Reading Text file and storing in map
Reading Text file and storing in map  Hi I have multiple text files. I want to read thoses files and store those records in map. Map will be of "LinkedHashMap<String, Map<String, String>>" type. Please let me know
Advertisements
Java class name and file name are different
Java class name and file name are different  Can we run a Java program having class name and file name different?   Hi Friend, No, you can't. It is necessary to save the java file with its class name otherwise
Java file get name
Java file get name In this section, you will learn how to get the name...(); System.out.println("File name is: " + st); } } Through the method getName() of File class, you can get the name of any file. Output:ADS_TO_REPLACE_2
ModuleNotFoundError: No module named 'file-or-name'
ModuleNotFoundError: No module named 'file-or-name'  Hi, My Python... 'file-or-name' How to remove the ModuleNotFoundError: No module named 'file-or-name' error? Thanks   Hi, In your python
Java Get File Name
Java Get File Name       In this section, you will study how to obtain the name of file.  In order to get the file name, we have provided the path of file 'Hello.txt
iterate through map and write the content in a separate file
iterate through map and write the content in a separate file  I am trying to save the data from file to a map, then iterate through map and write... into a separate file that already exists in computer. map: a d2rq:ClassMap
iterate through map and write the content in a separate file
iterate through map and write the content in a separate file  I am trying to save the data from file to a map, then iterate through map and write... into a separate file that already exists in computer. map: a d2rq:ClassMap
iterate through map and write the content in a separate file
iterate through map and write the content in a separate file  I am trying to save the data from file to a map, then iterate through map and write... into a separate file that already exists in computer. map: a d2rq:ClassMap
Constructing a File Name path
Constructing a File Name path   ... construct a file name path. By using the constructing filename path it is possible to set dynamic path, which is helpful for mapping local  file name
ModuleNotFoundError: No module named 'image-file-name-fixer'
ModuleNotFoundError: No module named 'image-file-name-fixer'  Hi...: No module named 'image-file-name-fixer' How to remove the ModuleNotFoundError: No module named 'image-file-name-fixer' error? Thanks   Hi
ModuleNotFoundError: No module named 'image-file-name-fixer'
ModuleNotFoundError: No module named 'image-file-name-fixer'  Hi...: No module named 'image-file-name-fixer' How to remove the ModuleNotFoundError: No module named 'image-file-name-fixer' error? Thanks   Hi
read from file and store using hash map
read from file and store using hash map  I was stuck with a java project where I have to read a file with two different concepts and store them differently in hashmap. My data file would be something like Adults: Name, xyz
Map words to line number in text file and show occurence
Map words to line number in text file and show occurence  hi i want to Map words to line number in text file and show occurrence of word in java coding
file upload and insert name into database - JSP-Servlet
file upload and insert name into database  Hi, I just joined as a fresher and was given task to upload a file and insert its name into database. The max size of the file can be 1mb. Along with the file name, there are other 2
Getting path name of uploading file in struts 2.1.8
Getting path name of uploading file in struts 2.1.8  In my question I used struts 2.8.1 instead of 2.1.8. Sorry
Getting path name of uploading file in struts 2.8.1
Getting path name of uploading file in struts 2.8.1  Hai! I am using struts 2.8.1. I want to upload file into database with the path name. How can I can get the original path name of the file in struts 2.8.1? It only display
why java file save as its class name
why java file save as its class name  hi,this is subbareddy vajrala.my doubt is why java files save as its class names
need to update key , value pair in map from properties file
need to update key , value pair in map from properties file  I have a map with key , value pair. with key as integer and value as string datatype. I want the keys and values to be dynamically updated into map. that is i have
How I Upload File and Store that file name in Database using JSP
How I Upload File and Store that file name in Database using JSP  Hi All, I m the beginner in JSP and I want to upload the file and store that file... form like Emp name, Emp id, city, address and one employee profile image(upload
Constructing a File Name path in Java
Constructing a File Name path    ... is helpful for mapping local  file name with the actual path of the file using... file name, using the static constant File.separator
map
map  using map, i want display message based on id selected [both are strings]   i do no   Hi Friend, Try the following code...) { Map map=new HashMap(); map.put("Message1","Hello
Map
Map  If I have an object implementing the Map interface in Java and I wish to iterate over every pair contained within it, what is the most efficient way of going through the map either iterator or for each loop or for loop
How to read text file to two different name array
How to read text file to two different name array   I have those numbers:12,4,9,5 numbers:19,12,1,1 how to put it in two different name array in text file to java
How to read text file to two different name array
How to read text file to two different name array   I have those numbers:12,4,9,5 numbers:19,12,1,1 how to put it in two different name array in text file to java
find jar file name from multiple set of jar files
find jar file name from multiple set of jar files   I would like to find jar file name from multiple set of jar files where the given class nameââ?¬Â?com.rational.ft.util.debugââ?¬Â
I want to know the given class name exists in which jar file?
I want to know the given class name exists in which jar file?   I want to know the given class name exists in which jar file? C:\Program Files\IBM... the name of the jar file where 'com.rational.ft.util.debug' class exists
How to retrieve file name and path of an excel spreadsheet imported into Oracle Database
How to retrieve file name and path of an excel spreadsheet imported into Oracle... Oracle database and I want to know how to retrieve the path of the file... of the spreadsheets imported (so I would know the location of the original source file
Name
Name  make a program that take a input from user in alphabet and show all the name of that character E.g User give character "B". The program shows all the human names which starts from B.   Java show all names
How to passed the ID's in MAP how to stored whaterver select the name that only ID should store in db using SWING/AWT?
How to passed the ID's in MAP how to stored whaterver select the name that only... ever the name is selected that id should be stored in database how to passed the ID's in MAP how to stored whaterver select the name that ID should store
Use Map to display file data into textfields
Use Map to display file data into textfields Collection framework allows.... You have mostly used ArrayList or Vector classes to store the file data. In this section, you will learn how to store the file data into HashMap in the form
Map interface
Map interface  What is the Map interface
need solution to get file name from path which should give by user
need solution to get file name from path which should give by user  how do i write a program in java that i should get file path from arguments.currently this code creates the file at d:\ but i need to get this file name
Reading xml file using dom parser in java with out using getelementby tag name
Reading xml file using dom parser in java with out using getelementby tag name  Hi, How to read the xml file using java with dom parser, but without using getelementbytag name, and also read the attribute values also. I had
Java file in memory
Java file in memory This section illustrates you how to map an entire file..., writing, mapping, and manipulating a file. ByteBuffer: This is an abstract class... except Boolean. map() method: This method of FileChannel class maps the region
Hash Map
Hash Map  how to add the hash map objects in the list and iterate the objects
Interactive map
Interactive map  hi........ i require map to be zoom in and enlarge the area and show its detail. Can anyone tel me how can this be done using java swings .... plz help
Map code
Map code  hi................ I have map of navi mumbai, where i want to see the location vashi, nerul, turbhe.... means want to zoom into this area and then again zoom in and see nerul location more properly or other location
hash map
hash map  write a program in hash map , that shows the value in asending order. but not key value. ex: key value ==== ===== k5 ashutosh k1 babita k7 debasis k2 vikas plz help me
Determining if two Filename paths refer to the same file.
to determine that the file name refers to the same file or not. What you need to do is to create two File object and pass the file name in the constructor of both...); System.out.println("It checks whether the file name paths are equal
Map Java Objects with Database tables
with setter and getter methods. Then map java class to table and database columns to Java class variables in hbm.xml file. <hibernate-mapping> <class name...Map Java Objects with Database tables  How to map Java Objects
Map
hash map
=2; HashMap<Integer,Test> map=new HashMap<Integer,Test>
Iterate Tag used with a Map.
Iterate Tag used with a Map.  How Iterate Tag used with a Map
parse map in java
parse map in java  What is a Parser? Can you give the source code to parse map in Java
Map java Object to database.
Map java Object to database.  How do you map Java Objects with Database tables
solution of k map in c
solution of k map in c  write a program in c to solve k-map with digital circuit
class name
class name  what is the class name of circle.java   how do i complie my jdk file, what happen s if i put in the correct commands and it still does not complie, what do i do next
ModuleNotFoundError: No module named 'map'
ModuleNotFoundError: No module named 'map'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'map' How to remove the ModuleNotFoundError: No module named 'map' error
Name unique
Name unique  I want to check whether the value which I give for the name textfield already exists in the database. In case if it exists , it should.... In other words, value for the name should be unique

Ads