当前位置:编程学习 > JAVA >>

老师留的一道题目,求大家帮忙解决,本人刚学java,对此题真的很吃力

1. Test File Permission

1.1 Feature to be tested:

A permission represents access to a system resource. In order for a
resource access to be allowed for a Java application running with a
security manager, the corresponding permission must be explicitly
granted to the code attempting the access via security policy file.

File permission is one class of the permissions you can grant to your
Java application.

File permission includes:
* read Permission to read.
* write Permission to write (which includes permission to create).
* execute Permission to execute. Allows Runtime.exec to be called.
Corresponds to SecurityManager.checkExec.
* delete Permission to delete. Allows File.delete to be called.
Corresponds to SecurityManager.checkDelete.

1.2 Homework
1.2.1 Write a test specification for the above four file permssions. Try
to come up with as many testing scenarios as you can.

1.2.2 Write testing code to test File write Permission. Requirements are:

* The main test code should be Java program which will be run as a
standalone Java application.
* The security manager should be installed via command line instead of
programmatically. And Policy file should be also specified on command line.
* Both positive and negative test cases are needed.
* Both Windows and Unix-like OS should be supported.
* The whole testing can be started by invoking a single script and then
run automatically. Arguments (such as JDK location, results location)
could be fed into this script on command line.
* Test result should be output to Stand Output. And if the testing fails
somehow (for example, JDK location doesn't exist), logs will be recorded
for investigation.
* Include the scenario of digitally signed code. (optional task) --------------------编程问答-------------------- ........楼下解答 --------------------编程问答-------------------- 翻译成中文先 --------------------编程问答-------------------- 全是英文啊,我顶啊

--------------------编程问答-------------------- 不着急吧?? 等我今天学习任务完成给你做。  

就是写点小例子 测试一下 文件权限吧。 --------------------编程问答-------------------- 海外留学朋友又有作业了,以前遇到了几个。 --------------------编程问答-------------------- 你们老师留的?这不是ORACLE的笔试题么?? --------------------编程问答-------------------- 这个还真看不懂 --------------------编程问答--------------------
引用 6 楼 allengaolin 的回复:
你们老师留的?这不是ORACLE的笔试题么??

这不是真相 --------------------编程问答-------------------- 就是写个程序验证文件的权限吧  运用io试试 --------------------编程问答-------------------- File类里面有 boolean canRead()  &&  boolean canWrite()  还有 booleandelete()  建议自己写着试试 实在不行的 可以call me  作业自己完成 --------------------编程问答-------------------- 无聊的题目,这些功能File类里全包含了 --------------------编程问答-------------------- 看不懂英文哈................ --------------------编程问答-------------------- 是关于文件读写的? --------------------编程问答-------------------- BuffReader/bufferrite..FileInputStream/FileOutputStream --------------------编程问答-------------------- 英文基础不怎么的 --------------------编程问答-------------------- 创建文件以及赋予权限

import java.io.File;
import java.io.IOException;

public class FilePermission {

public static void givePermission(String fileName) throws IOException{
File file = new File(fileName);
if(file.exists()){// 判断这个文件是不是存在
file.delete();// 删除这个文件
}
file.createNewFile();// 新建这个文件
System.out.println(fileName+" is created");

file.setReadable(true);// 设置这个文件可读权限

file.setWritable(true);// 可写权限

file.setExecutable(true);// 可执行权限

}
public static void main(String[] args) {
String fileName = "E:\\files\\test.txt";
try {
givePermission(fileName);
} catch (IOException e) {
e.printStackTrace();
}
}
}


测试这个文件的权限

import java.io.File;

public class TestPermission {

public static void main(String[] args) {
String fileName = "E:\\files\\test.txt";
File file = new File(fileName);

System.out.println(fileName+" 可读? "+file.canRead());
System.out.println(fileName+" 可写? "+file.canWrite());
System.out.println(fileName+" 可执行? "+file.canExecute());
}
}

--------------------编程问答-------------------- 以为英文是抛的异常呢。

完全没搞懂 --------------------编程问答-------------------- 看到英文就头大! --------------------编程问答-------------------- 英文啊!!!无能为力 --------------------编程问答-------------------- 这个老师有点给力啊  布置作业都用英文的 --------------------编程问答-------------------- 不是吧,你们老师是外交 --------------------编程问答-------------------- 我 现在发现 英语好重要了, 当初上初中的时候自己还跟老师 吵架啊。。。。 到现在 英语四级都 还没有过, 郁闷啊 --------------------编程问答-------------------- 查一下文档 就知道了 --------------------编程问答-------------------- 回顾一下流哪方面就好解决了啊
--------------------编程问答-------------------- 回16楼:要求跨平台的,直接用反斜线不好吧!应该用File.Separator(忘怎么拼了)吧? --------------------编程问答-------------------- 都是英文呢 --------------------编程问答-------------------- 这里还负责写作业啊 --------------------编程问答-------------------- 在国外就是这么混的,很正常 --------------------编程问答-------------------- 向前辈们学习,英文太牛了!
补充:Java ,  Java SE
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,