如何使文件无法在java中删除?或者给它访问权限也管理员不能删除它?(Windows 7)

时间:2021-10-07 15:57:17

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!!

我securty应用程序需要通过任何方式使文件无法解决或任何其他解决方案做同样的事情PLZ不要告诉我让它只读(它的安全)是在nio pakege的东西帮助我!

4 个解决方案

#1


1  

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)

不,你不能这样做,这样的应用程序不会被称为“安全应用程序”,而是某种形式的恶意软件,病毒,间谍软件等。管理员已经并且必须完全控制文件系统。唯一的例外是操作系统的某些关键文件,它们受操作系统本身的保护,因为如果删除它们会崩溃。 Java没有任何支持在文件系统上设置任何类型的安全权限(文件属性不完全是安全权限)

#2


1  

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

一点点黑客而不是完整的证据就是在你的java应用程序中打开文件流。这应该会阻止其他人删除该文件。一旦你的Java应用程序关闭,虽然它可以被删除。程序运行时,用户也无法编辑它。不是很好的解决方案,因为我认为它有太多的漏洞(例如,当java程序启动时需要知道文件名,需要一直运行java程序,用户无法做任何文件,用户可能只是杀死java进程等)但是对于一个小的利基要求它应该工作

#3


0  

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.

我担心我没有准备好证据,但我相信这是不可能的。 Oracle不会在Java中添加类似这样的功能,因为只要实现这一点,它们就会面临巨大的法律风险。正如Perception暗示的那样,它很容易被滥用。

Out of curiosity, what are you trying to accomplish with this?

出于好奇,你想用这个来完成什么?

#4


0  

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.

文件系统在此形成限制。基本上,管理员总是可以读取或写入文件,没有我知道的文件系统可以禁止任何人编辑。

#1


1  

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)

不,你不能这样做,这样的应用程序不会被称为“安全应用程序”,而是某种形式的恶意软件,病毒,间谍软件等。管理员已经并且必须完全控制文件系统。唯一的例外是操作系统的某些关键文件,它们受操作系统本身的保护,因为如果删除它们会崩溃。 Java没有任何支持在文件系统上设置任何类型的安全权限(文件属性不完全是安全权限)

#2


1  

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

一点点黑客而不是完整的证据就是在你的java应用程序中打开文件流。这应该会阻止其他人删除该文件。一旦你的Java应用程序关闭,虽然它可以被删除。程序运行时,用户也无法编辑它。不是很好的解决方案,因为我认为它有太多的漏洞(例如,当java程序启动时需要知道文件名,需要一直运行java程序,用户无法做任何文件,用户可能只是杀死java进程等)但是对于一个小的利基要求它应该工作

#3


0  

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.

我担心我没有准备好证据,但我相信这是不可能的。 Oracle不会在Java中添加类似这样的功能,因为只要实现这一点,它们就会面临巨大的法律风险。正如Perception暗示的那样,它很容易被滥用。

Out of curiosity, what are you trying to accomplish with this?

出于好奇,你想用这个来完成什么?

#4


0  

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.

文件系统在此形成限制。基本上,管理员总是可以读取或写入文件,没有我知道的文件系统可以禁止任何人编辑。