• Post Reply Bookmark Topic Watch Topic
  • New Topic

store movie title and path in hashmap  RSS feed

 
abrar alvi
Ranch Hand
Posts: 66
Eclipse IDE Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • 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....
 
nir sharma
Ranch Hand
Posts: 72
Eclipse IDE Java Tomcat Server
  • Mark post as helpful
  • send pies
  • 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
Eclipse IDE Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • 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 Java Tomcat Server
  • Mark post as helpful
  • send pies
  • 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..
 
John Jai
Rancher
Posts: 1776
  • Mark post as helpful
  • send pies
  • 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
Eclipse IDE Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks,

now the code is working fine....
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!