Why use Java. Net in Java security. Can securitymanager read any file?
•
Java
I just want to read and write some files in my java program So I use Java security. Security manager to manage it, but it doesn't seem satisfactory
Main. The java file is as follows
import java.io.*;
import java.util.*;
public class Main {
static private final String INPUT = "in.txt";
public static void main(String args[]) throws Exception {
FileInputStream instream = null;
BufferedReader reader = new BufferedReader(new FileReader(INPUT));
String tempString = null;
while ((tempString = reader.readLine()) != null) {
System.out.println(tempString);
}
}
}
And file / opt / Java The policy is as follows
grant {
permission java.io.FilePermission "./out.txt","write";
};
Then I ran away
java -Xss64m -Xms16m -Xmx512m -Djava.security.manager -Djava.security.policy=/opt/java.policy Main
But there is no error, the output is in txt. I tried other files and got the same results Why is that?
Solution
From Javadoc:
This is not to say that it is clear The code is not in the "directory": it is executed from the current working directory, which seems to mean
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码
