I securty app need to make file undeleteable by any way or any other Solution do same thing
plz dont tell me make it read only (its securty)
is there thing in nio pakege help me!!

- 7
- 3
-
6Making a file undeleteable by even admins would in itself be a security breach. – Perception Dec 08 '12 at 20:21
-
must be no one can edit file else creater file even admin – Yaser Haroun Dec 08 '12 at 20:24
4 Answers
A bit of a hack and not full proof would be to open a stream on the file in your java app. This should stop anyone else deleting the file. As soon as you java app shuts down though it could be deleted. While the program is running a user would not be able to edit it either. Not a great solution as I think it has too many holes (eg need to know filename when java program starts, need to have java program running all the time, user cannot do anything to file, user could just kill java process etc ) but for a small niche requirement it should work

- 15,272
- 18
- 86
- 131
-
Note that this increases disk usage and that is unwanted. Seems like the best 'solution' though. – siebz0r Dec 09 '12 at 00:29
-
Note that this only works on platforms that lock open files, such as Windows. Not all platforms do this. – user207421 Dec 09 '12 at 22:21
No, you can't do that and such an application wouldn't be called a "security application" but rather some form of malware, virus, spyware and so on. The administrator has and must have complete control of the file system. The only exceptions are certain critical files for the operating system, which are protected by the os itself, because it would crash if they were deleted. Java doesn't have any kind of support for setting any kind of security permission on the file system (file attributes aren't exactly security permissions)

- 66
- 3
I'm afraid I don't have a proof prepared, but I believe this is impossible. Oracle wouldn't add functions like that to Java, because they'd be at a huge legal risk just by making that possible. It could be easily abused, as Perception implied.
Out of curiosity, what are you trying to accomplish with this?

- 234
- 3
- 12
The file system forms a restriction here. Basicly the administrator can always read or write to files, there is no filesystem that I know of that makes it possible to prohibit editing by anyone.

- 18,867
- 14
- 64
- 107
-
NTFS permissions can be set up so that even an admin can't *accidentally* delete a file. It's pretty useless to do this for security reasons, though, as the admin can easily take ownership of a file to override the restrictions. – cHao Dec 08 '12 at 23:23