Java SecurityManager checkDelete()方法與示例

SecurityManager類的checkDelete()方法 (SecurityManager Class checkDelete() method)

  • checkDelete() method is available in java.lang package.

    checkDelete()方法在java.lang包中可用。

  • checkDelete() method calls checkPermission with FilePermission(filename,"delete").

    checkDelete()方法使用FilePermission(filename,“ delete”)調用checkPermission。

  • checkDelete() method is a non-static method, it is accessible with the class object only and if we try to access the method with the class name then we will get an error.

    checkDelete()方法是一種非靜態方法,僅可通過類對象訪問,如果嘗試使用類名稱訪問該方法,則會收到錯誤消息。

  • checkDelete() method may throw an exception at the time of deleting the file.

    在刪除文件時, checkDelete()方法可能會引發異常。

  • SecurityException – This exception may throw when the calling thread is not allowed to delete the file and it is called for the current security manager by using the delete() method of File class.

    SecurityException-如果不允許調用線程刪除文件,并且使用File類的delete()方法為當前的安全管理器調用此異常,則可能引發此異常。

    NullPointerException – This exception may throw when the given parameter is null.

    NullPointerException-如果給定參數為null,則可能引發此異常。

Syntax:

句法:

    public void checkDelete(String file_name);

Parameter(s):

參數:

  • String file_name – represents the system-dependent file name.

    字符串file_name –表示與系統有關的文件名。

Return value:

返回值:

The return type of this method is void, it returns nothing.

此方法的返回類型為void ,不返回任何內容。

Example:

例:

// Java program to demonstrate the example 
// of void checkDelete(String file_name)
// method of SecurityManager 
public class CheckDelete {
public static void main(String[] args) {
// By using setProperty() method is to set the policy property 
// with security manager
System.setProperty("java.security.policy", "file:/C:/java.policy");
// Instantiating a SecurityManager object
SecurityManager smgr = new SecurityManager();
// By using setSecurityManager() method is to set the
// security manager
System.setSecurityManager(smgr);
// By using checkDelete(String file_name) method is to check 
//that file is deleted or not
smgr.checkDelete("getProperties().doc");
// Display the message when file is deleted
System.out.println("File Deleted Successfuly..");
}
}

Output

輸出量

Exception in thread "main" java.security.AccessControlException: access denied ("java.io.FilePermission" "getProperties().doc" "delete")at java.base/java.security.AccessControlContext.checkPermission(AccessControlContext.java:472)at java.base/java.security.AccessController.checkPermission(AccessController.java:897)at java.base/java.lang.SecurityManager.checkPermission(SecurityManager.java:322)at java.base/java.lang.SecurityManager.checkDelete(SecurityManager.java:780)at CheckDelete.main(CheckDelete.java:20)

翻譯自: https://www.includehelp.com/java/securitymanager-checkdelete-method-with-example.aspx

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/379663.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/379663.shtml
英文地址,請注明出處:http://en.pswp.cn/news/379663.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

jQuery中的treeview插件

jQuery做樹狀結構真的很簡單,下面做一個最簡單的示例: 在html文件中引用: <link rel"stylesheet" href"../jquery.treeview.css" /> <link rel"stylesheet" href"../red-treeview.css" /> <link rel"styles…

Linux內核設計與實現---中斷和中斷處理程序

中斷和中斷處理程序1 中斷異常2 中斷處理程序上半部與下半部的對比3 注冊中斷處理程序釋放中斷處理程序4 編寫中斷處理程序重入和中斷處理程序共享的中斷處理程序中斷處理程序實例5 中斷上下文6 中斷處理機制的實現7 中斷控制禁止和激活中斷禁止指定中斷線中斷系統的狀態8 總結…

asp.net中的窗體身份驗證(最簡單篇)

在創建網站中&#xff0c;常常會使用到身份驗證。asp.net中內置了幾種身份驗證的方式&#xff0c;如Windows、Froms、Passport等。這幾種身份驗證的方式各有不同。一般來說&#xff0c;網站的身份驗證方式都會經過以下幾個步驟&#xff1a; 1、輸入用戶名和密碼&#xff0c;單擊…

bat文件調用dos命令 (dos淘金)

ECHO命令是大家都熟悉的DOS批處理命令的一條子命令&#xff0c;但它的一些功能和用法也許你并不是全都知道&#xff0c;不信你瞧&#xff1a; 1&#xff0e; 作為控制批處理命令在執行時是否顯示命令行自身的開關 格式&#xff1a;ECHO [ON|OFF] 如果想關閉“ECHO OFF”命令…

response細節點

一、 1&#xff09;、response獲得的流不需要手動關閉&#xff0c;Tomcat容器會幫你自動關閉 2&#xff09;、getWriter和getOutputStream不能同時調用 //error package com.itheima.content;import java.io.IOException; import javax.servlet.ServletException; import java…

Java RandomAccessFile writeBytes()方法與示例

RandomAccessFile類writeBytes()方法 (RandomAccessFile Class writeBytes() method) writeBytes() method is available in java.io package. writeBytes()方法在java.io包中可用。 writeBytes() method is used to write the sequence of bytes (i.e. string) to the file. E…

linux內核設計與實現---下半部和推后執行的工作

下半部和推后執行的工作1 下半部為什么要用下半部下半部的環境內核定時器2 軟中斷軟中斷的實現軟中斷處理程序執行軟中斷使用軟中斷3 tasklettasklet的實現使用taskletksoftirqd4 工作隊列工作隊列的實現工作、工作隊列和工作者線程之間的關系使用工作隊列5 下半部機制的選擇6 …

Jquery對復選框的操作

<from> 你的愛好是?<br/> <input type"checkbox" name"items" value"籃球" />籃球 <input type"checkbox" name"items" value"乒乓球" />乒乓球 <input type"checkbox" na…

HttpServletRequest(request的一些API)

一、request的運行流程 首先&#xff0c;自己寫一個web工程&#xff0c;也就是建一個工程&#xff1b;當把該web工程發布到Tomcat服務器當中&#xff0c;可以讓外界訪問&#xff0c;這就成了一個web應用。 在客戶端輸入一個網站&#xff0c;是web應用資源的地址URL&#xff0c…

DCI:James O. Coplien和Trygve Reenskau提出的新架構方法

http://www.infoq.com/cn/news/2009/05/dci-coplien-reenskau 轉載于:https://www.cnblogs.com/yelinpalace/archive/2009/06/13/1502573.html

Java ObjectStreamField getOffset()方法與示例

ObjectStreamField類的getOffset()方法 (ObjectStreamField Class getOffset() method) getOffset() method is available in java.io package. getOffset()方法在java.io包中可用。 getOffset() method is used to get the offset of this ObjectStreamField field. getOffse…

Mac VSCode配置C語言環境(可以調試)

Mac VSCode配置C語言環境c_cpp_properties.jsontasks.jsonlaunch.json新建一個文件夾&#xff0c;用vscode&#xff0c;然后再新建一個test.c文件。 #include <stdio.h>int main(void) {int a1,b1;int cab;printf("%d\n",c);return 0; }這篇文章說怎么配置c_c…

XmlPullParserException

今天在android的開發中約到一個問題 使用Ksoap2 訪問 WebService 拋出 XmlPullParserException 異常。 在網上淘了一下這個問題 http://www.eoeandroid.com/thread-70527-1-1.html 不能解決我的問題&#xff0c;求解轉載于:https://www.cnblogs.com/pengqinping/archive/2012/0…

vShpere Client在win 7 RC下和2008下 無法正常連接esx主機之解決辦法

vShpere Client在win 7 RC下和2008下 無法正常連接esx主機之解決辦法 在win7下和2008下打開client后連接esx主機會出現2個錯誤提示, 第一個是 第二個是 然后就連接失敗了,開始以為是CC的esx主機安裝有問題,后來找了找,借助了強大google工具,終于找到解決辦法.解決辦法如下: 1.從…

tooctalstring_Java Integer類toOctalString()方法的示例

tooctalstring整數類toOctalString()方法 (Integer class toOctalString() method) toOctalString() method is available in java.lang package. toOctalString()方法在java.lang包中可用。 toOctalString() method is used to represent an octal string of the given parame…

localhost與127.0.0.1之間的關系更改

其實localhost的默認IP地址為127.0.0.1&#xff0c;因為這是一種映射關系。 更改步驟如下&#xff1a; C:\Windows\System32\drivers\etc 下的hosts 打開hosts可以看到 更改即可

基于Hash表的排序--C語言

我們知道&#xff0c;C語言里面是沒有hash表的&#xff0c;但是我們可以用一個結構體表示&#xff0c;對結構體排序&#xff0c;我們可以用qsort排序。 下面我們用一個LeedCode上面的一道題目講解。 347. 前 K 個高頻元素 這個題目是讓我們求解前k個高頻元素&#xff0c;求解思…

ORACLE10g R2及PATH官方下載地址

ORACLE10g R2及PATH官方下載地址 Oracle Database 10g Release 2 (10.2.0.1.0) Enterprise/Standard Edition for Microsoft Windows (32-bit)http://download.oracle.com/otn/nt/oracle10g/10201/10201_database_win32.zip http://download.oracle.com/otn/nt/oracle10g/102…

[網摘]Javascript中最常用的55個經典技巧

1. οncοntextmenu"window.event.returnValuefalse" 將徹底屏蔽鼠標右鍵<table border οncοntextmenureturn(false)><td>no</table> 可用于Table 2. <body onselectstart"return false"> 取消選取、防止復制 3. οnpaste"…

Java集合unmodifiableMap()方法及示例

集合類unmodifiableMap()方法 (Collections Class unmodifiableMap() method) unmodifiableMap() method is available in java.util package. unmodifiableMap()方法在java.util包中可用。 unmodifiableMap() method is used to get a non-modifiable view of the given Map (…