• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

store movie title and path in hashmap

 
Ranch Hand
Posts: 66
Netbeans IDE Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,

this is a code which scans a given movie directory and stores the location of each files in fileaddress.....

my problem:
1. I want also to store the file name as well as the file path(which i am getting through this code)...
2. Then store the file name and path in a HashMap after getting the same....





Help me....
 
Ranch Hand
Posts: 72
Eclipse IDE Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

abrar alvi wrote:


you can use fileaddress.getParent(); to get the parent directory and your variable filename already contain the file name or you can also use fileaddress.getName(); it wont make any difference though.
then you can store those in hashmap.
This should solve the issue but if not then can I know what is the issue you are facing?
 
abrar alvi
Ranch Hand
Posts: 66
Netbeans IDE Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

nir sharma wrote:

abrar alvi wrote:


you can use fileaddress.getParent(); to get the parent directory and your variable filename already contain the file name or you can also use fileaddress.getName(); it wont make any difference though.
then you can store those in hashmap.
This should solve the issue but if not then can I know what is the issue you are facing?



Thank you Nir,

i have included HashMap to store the file name and its path....

problem now: filename is only returning the directory name but i need the file name inside it to be returned

this is my modified code:




this is the output:

{New Folder=C:\Documents and Settings\Abrar Alvi\Desktop\New Folder}
{New Folder (2)=C:\Documents and Settings\Abrar Alvi\Desktop\New Folder, New Folder=C:\Documents and Settings\Abrar Alvi\Desktop\New Folder}
{New Folder (3)=C:\Documents and Settings\Abrar Alvi\Desktop\New Folder, New Folder (2)=C:\Documents and Settings\Abrar Alvi\Desktop\New Folder, New Folder=C:\Documents and Settings\Abrar Alvi\Desktop\New Folder}
{New Folder (4)=C:\Documents and Settings\Abrar Alvi\Desktop\New Folder, New Folder (3)=C:\Documents and Settings\Abrar Alvi\Desktop\New Folder, New Folder (2)=C:\Documents and Settings\Abrar Alvi\Desktop\New Folder, New Folder=C:\Documents and Settings\Abrar Alvi\Desktop\New Folder}
 
nir sharma
Ranch Hand
Posts: 72
Eclipse IDE Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I made few changes in your code.



these are the changes to help you get the desired result but you need to make changes I have mentioned few as comments in the code
hope this help..
 
Rancher
Posts: 1776
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Instead of using list() method that returns String array of file names, you can use the listFiles() method that returns an array of File objects. Iterate it, get store the file name as key and file path as value in the HashMap.

 
abrar alvi
Ranch Hand
Posts: 66
Netbeans IDE Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks,

now the code is working fine....
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic