I want to keep track of multiple files in a location in a unix box, and delete them if no one is using them for a long time. I am trying to search for reference counting but did not get much help on google. I also saw FileTime in java 7 which can give me the last accessed time , but i have to the above work using java 6. If anyone has any ideas or good reference to reference counting and how i can use it, it will be great.
3 Answers
You can use apache common IO. Set observer on your dir which checks the dir and notifying listeners of create, change or delete eventslisten. By this it is possible to track on which dir has been working by user and others are not.

- 40,646
- 13
- 77
- 103
-
i want to delete per file basis . The directory will have many files and i want to delete files which are not being used. – randeepsp Aug 29 '12 at 05:30
-
you can do even on some specific file or all file. [Check api](http://commons.apache.org/io/api-release/org/apache/commons/io/monitor/FileAlterationObserver.html) – Subhrajyoti Majumder Aug 29 '12 at 07:47
Okay, so we want last access time.
You can have a read of Get the Last Access Time for a File for some further info.
You could try and have a look at http://jdevel.wordpress.com/2011/04/08/file-last-access-time-in-java-on-linux/ for a possible soultion, but this is Linux, not Unix.

- 1
- 1

- 343,457
- 22
- 230
- 366
-
the file is not going to be modified, it is only read once it is created. – randeepsp Aug 29 '12 at 04:37
-
There is no module for File watching till JDK 1.6. What you can do is, you can write your own file watcher by seeing the
lastModified() method of the java.io.File class.
It returns you the last modified time as a long value and you keep a watch on this file during a regular interval. If the total time difference
(presentTime - lastModifiedTime)
exceeds you time criteria, you can delete the file.

- 3,278
- 3
- 16
- 29
-
the file is not going to be modified, it is only read once it is created – randeepsp Aug 29 '12 at 11:10
-
here your creation time is last modified time. so you need to execute currenttime-creationtime and if that exceeds your time limit , delete the file. – sakthisundar Aug 29 '12 at 12:30