java seterr_java System 类里out和err怎么赋值的?没找到源码 initializeSystemClass也没有找到....求大神讲解一下...

展开全部

这是 initializeSystemClass 源码,就在 System 类中,在System类的源码中搜索一下 initializeSystemClass 就可以找到了。private static void initializeSystemClass() {

props = new Properties();

initProperties(props);  // initialized by the VM

sun.misc.VM.saveAndRemoveProperties(props);

lineSeparator = props.getProperty("line.separator");

sun.misc.Version.init();

FileInputStream fdIn = new FileInputStream(FileDescriptor.in);

FileOutputStream fdOut = new FileOutputStream(FileDescriptor.out);

FileOutputStream fdErr = new FileOutputStream(FileDescriptor.err);

setIn0(new BufferedInputStream(fdIn));

setOut0(newPrintStream(fdOut, props.getProperty("sun.stdout.encoding")));

setErr0(newPrintStream(fdErr, props.getProperty("sun.stderr.encoding")));

loadLibrary("zip");

// Setup Java signal handlers for HUP, TERM, and INT (where available).

Terminator.setup();

sun.misc.VM.initializeOSEnvironment();

Thread current = Thread.currentThread();

current.getThreadGroup().add(current);

// register shared secrets

setJavaLangAccess();

sun.misc.VM.booted();

}

其中这几句代码就是用来初始化,标准输入流,636f70793231313335323631343130323136353331333365643531标准输出流,标准错误输出流的。FileInputStream fdIn = new FileInputStream(FileDescriptor.in);

FileOutputStream fdOut = new FileOutputStream(FileDescriptor.out);

FileOutputStream fdErr = new FileOutputStream(FileDescriptor.err);

setIn0(new BufferedInputStream(fdIn));

setOut0(newPrintStream(fdOut, props.getProperty("sun.stdout.encoding")));

setErr0(newPrintStream(fdErr, props.getProperty("sun.stderr.encoding")));

这其中 setOut0 就是用来设置 System.out  的,setOut0 看不到源码的,它是在java虚拟中的。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值