Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Beginners Stoting file name in Map

Have Programming Question? Ask it here!
 
 
 


Pragati
Stoting file name in Map
2 Answer(s)      3 years and 6 months ago
Posted in : Java Beginners


how to store id and file name in map


Advertisement
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
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
Java file get name
Java file get name In this section, you will learn how to get the name... the name of the file. Here is the code: import java.io.*; public class... name is: " + st); } } Through the method getName() of File class, you can
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
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
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
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
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
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
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
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
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
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
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
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
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
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
Map interface
Map interface  What is the Map interface
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
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
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
Map
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
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
hash map
=2; HashMap<Integer,Test> map=new HashMap<Integer,Test>
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..., and manipulating a file. ByteBuffer: This is an abstract class which provides.... map() method: This method of FileChannel class maps the region of the channel's
parse map in java
parse map in java  What is a Parser? Can you give the source code to parse map in Java
solution of k map in c
solution of k map in c  write a program in c to solve k-map with digital circuit
Map java Object to database.
Map java Object to database.  How do you map Java Objects with Database tables
Iterate Tag used with a Map.
Iterate Tag used with a Map.  How Iterate Tag used with a Map
about google map
about google map  how to add google map in website
about google map
about google map  how to add google map in website
Java tree map trouble
Java tree map trouble  This is a project for a class, and I am totally stuck! I've created a tree map using an input text file. I split the lines into fields so that I could work with 2 elements from the file. It appears
add google map javascript
add google map javascript  How can i add google map using javascript in my web page?   Search for the " Google Maps Javascript API" it will allow you to embed the Google Map into your web Page
map on web page
map on web page   i want to insert an area map in my web page how can i do it ? please answer me soon. Its urgent
Google Map Integration - Ajax
Google Map Integration  Hi All, I am working on a vehicle tracking system project. I have to read data from sql server database and map the vehicle position in google map. I need to use ajax as the data is updated in every
Using of [] operator of EL with the Map
Map key or a bean property name as well as the access to arrays and Lists. Map stores the values in the form of a key- value pair. Map can't have a duplicate...Using [ ] operator of EL with the Map   
Advertisements
 

 

 

DMCA.com