Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How to check for the changed file  RSS feed

 
sathish
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Everyone
I have a file/folder which needs to be monitored for period of time. How can i check to see if the new files have been added or deleted or changed in the directory? can i use XML with java to take a snap shot of the file and compare when it changes? if so how do you do it?
thanks
sathish
 
Grant Crofton
Ranch Hand
Posts: 154
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can use some of java.io.File's methods to check.
This can be used on directories to find out how many files they contain etc., and with files they tell you the file's 'last modified' attribute.
If you need to get into more detail, you can calculate a checksum for a file, store this (normally it's a long), and, when you need to check if the file's changed, calculate it's checksum again and compare them.
If you want to find out about checksums, look at java.uitl.zip.CRC32 or ADlER32.
Hope that helps. Grant.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!