sun.security.action.GetPropertyAction class 在 java

sun.security.action.GetPropertyAction class in java

今天我在java学习IO。当我查看 BufferedWriter class 中的 lineSeparator 字符串时,我看到了语句

lineSeparator = java.security.AccessController.doPrivileged(
        new sun.security.action.GetPropertyAction("line.separator"));

初始化 lineSeparator 字符串。但是我没有找到

sun.security.action.GetPropertyAction(String args)

class java 来源。所以我很困惑 java 如何使用这个 class,它不在 java 源代码中。所以告诉我:

Java 有这个 class 你可以从 here, but you shouldn't use sun(now oracle package at your code) source 这里看到为什么不应该使用它的原因。

的含义
java.security.AccessController.doPrivileged(
        new sun.security.action.GetPropertyAction("line.separator"));

The code that uses doPrivileged says "Give me the value of the property, if the current class (where this line of code is in) is allowed to read it."

here还有一个讨论更好理解

编辑: 它在您的 JDK 程序下 Files\Java\jdk1.8.0_25\jre\lib\rt .jar可以学习rt.jardetails

现在是 2020 年了,这种情况仍然存在。解决该问题的一种快速方法是使用已安装的 JDK 而不是来自 eclipse 安装的 JRE。转到 Windows>首选项>Java>已安装的 JRE 并添加已安装的 JDK 并将其用作默认值。