SecurityManager实例

:大哥哥,securityManager是什么

:小妹妹,用了就知道

 

一个这个东西的小例子:

 

package com.basic;

import java.io.FileOutputStream;
import junit.framework.TestCase;

public class SecurityManagerTest extends TestCase {

	/**
	 * 权限设置
	 * 权限文件内容:(f:/my.policy)
	 * grant{
	 * permission java.io.FilePermission "F:/*", "read";
     * };
	 * @throws Exception
	 */
	public void testFilePermission() throws Exception{
		System.setProperty("java.security.policy", "F:/my.policy");
		System.setSecurityManager(new SecurityManager());
		FileOutputStream out = new FileOutputStream("f:/temp.sql",true);
		out.write("test".getBytes());
		out.flush();
	}
}
 

 

你可能感兴趣的:(实例,securitymanager)