• Post Reply Bookmark Topic Watch Topic
  • New Topic

help needed in Hashtable reading and removing files.  RSS feed

 
Bala Raju Mandala
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

I need your help in solving a problem i am facing.

I am reading files from a particular folder and storing them into Hashtable(Key is filename and value is file object).

I need to read this Hashtable for a particular file extention. After getting particular file, i need to search associated files of first file in the same Hashtable. I need to store all these files in a list.

This part is working fine, but problem here is as i am reading the Hashtable sequentially, the same process will repeatin for the each associated file also. I tried to remove the associated files from Hashtable once they found but it is throwing

Exception in thread "main" java.util.ConcurrentModificationException
at java.util.Hashtable$Enumerator.next(Unknown Source)
at HashEx.main(HashEx.java:33)

can anybody give some suggestions so that i can avoid of reading associated files.
 
Balasubramanian Chandrasekaran
Ranch Hand
Posts: 215
Firefox Browser Linux VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Bala,

.... but problem here is as i am reading the Hashtable sequentially, the same process will repeatin for the each associated file also. I tried to remove the associated files from Hashtable once they found but it is throwing

Exception in thread "main" java.util.ConcurrentModificationException
at java.util.Hashtable$Enumerator.next(Unknown Source)
at HashEx.main(HashEx.java:33)



From API about ConcurrentModificationException:

This exception may be thrown by methods that have detected concurrent modification of an object when such modification is not permissible.

For example, it is not generally permissible for one thread to modify a Collection while another thread is iterating over it.


I think synchronization will solve your problem.
[ June 11, 2008: Message edited by: Balasubramanian Chandrasekaran ]
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!