Java基础-015-System.java常用类
Java基础-015-System.java常用类
- 1、标准输入输出
- 2、获取属性
- 3、System.java初始化
- 4、设置标准输出System.out
java/lang/System.java
1、标准输入输出
System.in
、System.out
public class Test {public static void main(String[] args) {String charsetName = String.valueOf(Charset.defaultCharset());System.out.println("System.out.println : charsetName="+charsetName);Scanner s = new Scanner(System.in,"gbk");if (s.hasNext()) {String str1 = s.next();System.out.println("输入的数据为:" + str1);}}
}
2、获取属性
jdk/internal/util/SystemProps.java
、java/lang/VersionProps.java
、jdk/internal/util/StaticProperty.java
System.out.println("System.getProperty(\"sun.jnu.encoding\")="+System.getProperty("sun.jnu.encoding"));
System.out.println("System.getProperty(\"native.encoding\")="+System.getProperty("native.encoding"));
System.out.println("System.getProperty(\"sun.stdout.encoding\")="+System.getProperty("sun.stdout.encoding"));
System.out.println("System.getProperty(\"user.dir\")="+System.getProperty("user.dir"));
System.out.println("System.getProperties()="+System.getProperties());
System.getProperties()={java.specification.version=18, sun.cpu.isalist=amd64, sun.jnu.encoding=GBK, java.class.path=D:\IdeaProjects\Jcmd\build\classes\java\main;D:\IdeaProjects\Jcmd\build\resources\main;D:\gradle\envs\caches\modules-2\files-2.1\com.gitee.xhbruce.xhLog\xLog\1.0.3\8734bf5379ee7cee34cf10ab875570208b2360ca\xLog-1.0.3.jar;D:\gradle\envs\caches\modules-2\files-2.1\org.apache.commons\commons-exec\1.3\8dfb9facd0830a27b1b5f29f84593f0aeee7773b\commons-exec-1.3.jar, java.vm.vendor=Oracle Corporation, sun.arch.data.model=64, user.variant=, java.vendor.url=https://java.oracle.com/, java.vm.specification.version=18, os.name=Windows 10, user.country=CN, sun.java.launcher=SUN_STANDARD, sun.boot.library.path=D:\ProgramFiles\Java\jdk-18.0.1.1\bin, sun.java.command=org.xhbruce.Test, jdk.debug=release, sun.cpu.endian=little, user.home=C:\Users\Administrator, user.language=zh, java.specification.vendor=Oracle Corporation, java.version.date=2022-04-22, java.home=D:\ProgramFiles\Java\jdk-18.0.1.1, file.separator=\, java.vm.compressedOopsMode=Zero based, line.separator=
, java.vm.specification.vendor=Oracle Corporation, java.specification.name=Java Platform API Specification, user.script=, sun.management.compiler=HotSpot 64-Bit Tiered Compilers, java.runtime.version=18.0.1.1+2-6, user.name=xhbruce, path.separator=;, os.version=10.0, java.runtime.name=Java(TM) SE Runtime Environment, file.encoding=UTF-8, java.vm.name=Java HotSpot(TM) 64-Bit Server VM, java.vendor.url.bug=https://bugreport.java.com/bugreport/, java.io.tmpdir=C:\Users\ADMINI~1\AppData\Local\Temp\, java.version=18.0.1.1, user.dir=D:\IdeaProjects\Jcmd, os.arch=amd64, java.vm.specification.name=Java Virtual Machine Specification, sun.os.patch.level=, native.encoding=GBK, java.library.path=D:\ProgramFiles\Java\jdk-18.0.1.1\bin;C:\WINDOWS\Sun\Java\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files\NVIDIA Corporation\NVIDIA NvDLISR;C:\ProgramData\chocolatey\bin;D:\Books\Linux\bat;D:\AndroidStudio\Sdk\tools;D:\AndroidStudio\Sdk\platform-tools;D:\AndroidStudio\Sdk\cmake\3.6.4111459\bin;D:\AndroidStudio;D:\ProgramFiles\Java\Openjfx\javafx-sdk-21\lib;D:\ProgramFiles\Java\jdk-18.0.1.1\bin;D:\ProgramFiles\Java\jdk-18.0.1.1\jre;C:\Program Files\mingw64\bin;%CTAGS_HOME%;%TOMCAT_HOME%\bin;C:\Program Files\nodejs\;C:\Program Files\Git\cmd;D:\ProgramFiles\ffmpeg\bin;D:\gradle\envs;C:\Users\Administrator\AppData\Local\Microsoft\WindowsApps;C:\Users\Administrator\AppData\Roaming\npm;G:\ProgramFiles\JetBrains\Toolbox\scripts;D:\Program Files\Microsoft VS Code\bin;C:\Users\Administrator\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\Scripts;;., java.vm.info=mixed mode, sharing, java.vendor=Oracle Corporation, java.vm.version=18.0.1.1+2-6, sun.io.unicode.encoding=UnicodeLittle, java.class.version=62.0}
属性字段 | 功能 | 获取结果 |
---|---|---|
java.specification.version | 18 | |
sun.cpu.isalist | amd64 | |
sun.jnu.encoding | GBK | |
java.class.path | D:\IdeaProjects\Jcmd\build\classes\java\main;… | |
java.vm.vendor | Oracle Corporation | |
sun.arch.data.model | 64 | |
user.variant | ||
java.vendor.url | https://java.oracle.com/ | |
java.vm.specification.version | 18 | |
os.name | 系统名称 | Windows 10 |
user.country | 系统国家 | CN |
sun.java.launcher | SUN_STANDARD | |
sun.boot.library.path | D:\ProgramFiles\Java\jdk-18.0.1.1\bin | |
sun.java.command | org.xhbruce.Test | |
jdk.debug | release | |
sun.cpu.endian | little | |
user.home | 系统用户文件夹 | C:\Users\Administrator |
user.language | 系统语言 | zh |
java.specification.vendor | Oracle Corporation | |
java.version.date | java版本日期 | 2022-04-22 |
java.home | java路径 | D:\ProgramFiles\Java\jdk-18.0.1.1 |
file.separator | 文件分隔符 | \ |
java.vm.compressedOopsMode | Zero based | |
line.separator | ||
java.vm.specification.vendor | Oracle Corporation | |
java.specification.name | Java Platform API Specification | |
user.script | ||
sun.management.compiler | HotSpot 64-Bit Tiered Compilers | |
java.runtime.version | 18.0.1.1+2-6 | |
user.name | xhbruce | |
path.separator | ; | |
os.version | 10.0 | |
java.runtime.name | Java™ SE Runtime Environment | |
file.encoding | UTF-8 | |
java.vm.name | Java HotSpot™ 64-Bit Server VM | |
java.vendor.url.bug | https://bugreport.java.com/bugreport/ | |
java.io.tmpdir | C:\Users\ADMINI~1\AppData\Local\Temp, java.version=18.0.1.1 | |
user.dir | 当前路径 | D:\IdeaProjects\Jcmd |
os.arch | amd64 | |
java.vm.specification.name | Java Virtual Machine Specification | |
sun.os.patch.level | ||
native.encoding | GBK | |
java.library.path | 系统环境配置path | D:\ProgramFiles\Java\jdk-18.0.1.1\bin;C:\WINDOWS\Sun\Java\bin;C:\WINDOWS\system32;… |
java.vm.info | mixed mode, sharing | |
java.vendor | Oracle Corporation | |
java.vm.version | 18.0.1.1+2-6 | |
sun.io.unicode.encoding | UnicodeLittle | |
java.class.version | 62.0 |
3、System.java初始化
SystemProps.initProperties()
、VersionProps.init(tempProps)
、VM.saveProperties(tempProps)
、StaticProperty.javaHome()
系统属性和java相关属性初始化setIn0
、setOut0
、setErr0
标准输出输出配置
/*** Initialize the system class. Called after thread initialization.*/private static void initPhase1() {// register the shared secrets - do this first, since SystemProps.initProperties// might initialize CharsetDecoders that rely on itsetJavaLangAccess();// VM might invoke JNU_NewStringPlatform() to set those encoding// sensitive properties (user.home, user.name, boot.class.path, etc.)// during "props" initialization.// The charset is initialized in System.c and does not depend on the Properties.Map<String, String> tempProps = SystemProps.initProperties();VersionProps.init(tempProps);// There are certain system configurations that may be controlled by// VM options such as the maximum amount of direct memory and// Integer cache size used to support the object identity semantics// of autoboxing. Typically, the library will obtain these values// from the properties set by the VM. If the properties are for// internal implementation use only, these properties should be// masked from the system properties.//// Save a private copy of the system properties object that// can only be accessed by the internal implementation.VM.saveProperties(tempProps);props = createProperties(tempProps);// Check if sun.jnu.encoding is supported. If not, replace it with UTF-8.var jnuEncoding = props.getProperty("sun.jnu.encoding");if (jnuEncoding == null || !Charset.isSupported(jnuEncoding)) {notSupportedJnuEncoding = jnuEncoding == null ? "null" : jnuEncoding;props.setProperty("sun.jnu.encoding", "UTF-8");}StaticProperty.javaHome(); // Load StaticProperty to cache the property valueslineSeparator = props.getProperty("line.separator");FileInputStream fdIn = new FileInputStream(FileDescriptor.in);FileOutputStream fdOut = new FileOutputStream(FileDescriptor.out);FileOutputStream fdErr = new FileOutputStream(FileDescriptor.err);setIn0(new BufferedInputStream(fdIn));// sun.stdout/err.encoding are set when the VM is associated with the terminal,// thus they are equivalent to Console.charset(), otherwise the encoding// defaults to native.encodingsetOut0(newPrintStream(fdOut, props.getProperty("sun.stdout.encoding", StaticProperty.nativeEncoding())));setErr0(newPrintStream(fdErr, props.getProperty("sun.stderr.encoding", StaticProperty.nativeEncoding())));// Setup Java signal handlers for HUP, TERM, and INT (where available).Terminator.setup();// Initialize any miscellaneous operating system settings that need to be// set for the class libraries. Currently this is no-op everywhere except// for Windows where the process-wide error mode is set before the java.io// classes are used.VM.initializeOSEnvironment();// The main thread is not added to its thread group in the same// way as other threads; we must do it ourselves here.Thread current = Thread.currentThread();current.getThreadGroup().add(current);// Subsystems that are invoked during initialization can invoke// VM.isBooted() in order to avoid doing things that should// wait until the VM is fully initialized. The initialization level// is incremented from 0 to 1 here to indicate the first phase of// initialization has completed.// IMPORTANT: Ensure that this remains the last initialization action!VM.initLevel(1);}
4、设置标准输出System.out
java/io/PrintStream.java
- 主要用于IDE和系统终端输出设置编码
Encoding
- 设置输出到文件
String stdoutEncoding = System.getProperty("file.encoding")
if (!System.out.charset().name().equals(stdoutEncoding)) {try {PrintStream ps = new PrintStream(System.out, true, stdoutEncoding);System.setOut(ps);} catch (UnsupportedEncodingException e) {throw new RuntimeException(e);}
}
System.out.println("#########################");
System.out.println("System.out" + System.out);
try {PrintStream ps = new PrintStream(new File(System.getProperty("user.dir")+"/test.txt"), stdoutEncoding);System.setOut(ps);
} catch (UnsupportedEncodingException | FileNotFoundException e) {throw new RuntimeException(e);
}
System.out.println("System.out" + System.out);
System.out.println("System.out.charset() = " + System.out.charset());
System.out.println("native.encoding = " + System.getProperty("native.encoding"));
System.out.println("sun.jnu.encoding = " + System.getProperty("sun.jnu.encoding"));
System.out.println("sun.stdout.encoding = " + System.getProperty("sun.stdout.encoding"));
System.out.println("sun.io.unicode.encoding = " + System.getProperty("sun.io.unicode.encoding"));
System.out.println("#########################");
System.out.println("你好 java");
XLog.d("你好 xhburce");
相关文章:

Java基础-015-System.java常用类
Java基础-015-System.java常用类 1、标准输入输出2、获取属性3、System.java初始化4、设置标准输出System.out java/lang/System.java 1、标准输入输出 System.in、System.out public class Test {public static void main(String[] args) {String charsetName String.valueOf…...

Flutter笔记:发布一个模块 scale_design - (移动端)设计师尺寸适配工具
Flutter笔记 发布一个模块scale_design设计师尺寸适配工具与常用组件库 作者:李俊才 (jcLee95):https://blog.csdn.net/qq_28550263 邮箱 :291148484163.com 本文地址:https://blog.csdn.net/qq_28550263/a…...
torch增加维度操作
使用none作为占位符 在Python中,None 表示空值或占位符。 在masked_pos[:, :, None]这个切片操作中,None 被用作一个占位符,以改变张量的维度。这通常用于将一维张量变为二维张量,或者改变张量的形状。 具体来说,ma…...

软件测试面试题及答案2024
1、你们的缺陷等级如何划分的?☆☆☆☆☆ 我们的缺陷一般分为四个等级,致命级,严重级,一般级和轻微级。致命级指能够导致软件程序无法使用的缺陷,比如宕机,崩溃,手机APP的闪退,数据…...
C现代方法(第18章)笔记——声明
文章目录 第18章 声明18.1 声明的语法18.2 存储类型18.2.1 变量的性质18.2.2 auto存储类型18.2.3 static存储类型18.2.4 extern存储类型18.2.5 register存储类型18.2.6 函数的存储类型18.2.7 小结 18.3 类型限定符18.4 声明符18.4.1 解释复杂声明18.4.2 使用类型定义来简化声明…...

Spring Data Redis + RabbitMQ - 基于 string + hash 实现缓存,计数(高内聚)
目录 一、Spring Data Redis 1.1、缓存功能(分析) 1.2、案例实现 一、Spring Data Redis 1.1、缓存功能(分析) hash 类型存储缓存相比于 string 类型就有更多的更合适的使用场景. 例如,我有以下这样一个 UserInfo 信息 假设这样一个场景就是:万一只想获取其中某一个…...

【四、http】go的http的文件下载
一、日常下载图片到本地 //下载文件func downloadfile(url, filename string) {r, err : http.Get(url)if err ! nil {fmt.Println("err", err.Error())}defer r.Body.Close()f, err : os.Create(filename)if err ! nil {fmt.Println("err", err.Error())…...

Java web(六):FilterListenerAJAX
文章目录 一、Filter1.1 基本介绍1.2 过滤器的执行流程1.3 拦截路径配置1.4 过滤器链1.5 案例 二、Listener三、AJAX3.1 快速入门3.2 Axios异步框架 四、 JSON4.1 JSON基础语法4.2 Fastjson 五、 案例JSONAxiosServlet Java web的三大组件:Servlet、Filter、Listene…...

初识jQuery
文章目录 一、jQuery介绍二、Jquery优势三、jQuery版本四、jQuery对象jQuery的引用js代码与jQuery代码对比标签对象与jQuery对象 五、jQuery查找标签1.基本选择器2.组合选择器3.层次选择器4.属性选择器5.基本筛选器6.表单筛选器 六、筛选器方法七、操作标签1.class操作2.文本操…...
MATLAB算法实战应用案例精讲-【图像处理】计算机视觉(最终篇)
目录 知识储备 线阵相机调试 1.相机型号参数 2.相机软件安装 3.编码器连接方式 4.采集卡说明...
repo执行出现/usr/bin/env: ‘python’: No such file or directory问题
下载 Repo 工具,并确保它可执行: curl https://storage.googleapis.com/git-repo-downloads/repo > ~/bin/repochmod ax ~/bin/repo 执行 repo version报错: $ repo version /usr/bin/env: ‘python’: No such file or directory查看c…...

算法模板之单调栈解密 | 图文详解
🌈个人主页:聆风吟 🔥系列专栏:算法模板、数据结构 🔖少年有梦不应止于心动,更要付诸行动。 文章目录 📋前言一. ⛳️单调栈讲解1.1 🔔单调栈的定义1.2 🔔如何维护一个单…...
187.重复的 DNA 序列
题目来源: leetcode题目,网址:187. 重复的DNA序列 - 力扣(LeetCode) 解题思路: 使用两个哈希表,一个存放已遍历过的长度为 10 的字符串,另一个存放重复的长度为 10 的字符串。顺…...

Sentinel黑白名单授权规则解读
目录 基本介绍 代码实战 架构说明 RequestOriginParser的实现类 网关添加请求头 配置授权规则 基本介绍 授权规则可以对请求方来源做判断和控制。 很多时候,我们需要根据调用来源来判断该次请求是否允许放行,这时候可以使用 Sentinel 的来源…...
Spring底层原理学习笔记--第二讲--(BeanFactory实现与ApplicaitonContext实现)
BeanFactory实现 package com.lucifer.itheima.a02;import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.config.BeanFactoryPostProcessor; import org.springframework.beans.fac…...
云原生|kubernetes |kubelet服务加入系统守护进程supervisor(centos7系统下演示通过)
前言: kubelet 是 Kubernetes 集群中的一个重要组件,运行在每个节点上,负责管理该节点上的容器和Pod。它与控制平面(如 API Server 和 kube-controller-manager)通信,确保节点上的容器与期望的状态保持一致…...

onnx 模型加载部署运行方式
1.通过文件路径的onnx模型加载方式: 在onnxruntime下面的主要函数:session Ort::Session(env, w_modelPath.c_str(), sessionOptions); 这里的文件路径是宽字节的,通过onnx文件路径直接加载模型。 在opencv下使用dnn加载onnx模型的主要函数: std::string model…...

第68讲:MySQL触发器的核心概念以及常见的触发类型应用案例
文章目录 1.触发器的概念2.触发器操作的语法结构3.各类触发器的典型应用案例3.1.需求描述以及实现思路3.2.创建日志表3.3.INSERT类型的触发器3.4.UPDATE类型的触发器3.5.DELETE类型的触发器 1.触发器的概念 触发器是与表中数据相关的数据库对象,当表中的数据产生in…...

VS Code 开发 Spring Boot 类型的项目
在VS Code中开发Spring Boot的项目, 可以导入如下的扩展: Spring Boot ToolsSpring InitializrSpring Boot Dashboard 比较建议的方式是安装Spring Boot Extension Pack, 这里面就包含了上面的扩展。 安装方式就是在扩展查找 “Spring Boot…...

数据中心加密:保障数据安全的重要一环
随着信息化的快速发展,数据已经成为企业的重要资产,数据安全也成为了企业面临的重大挑战。数据中心作为企业数据存储和管理的重要场所,其安全性对于整个企业的数据安全具有至关重要的作用。而数据中心加密则是保障数据安全的重要一环。本文将…...

智慧医疗能源事业线深度画像分析(上)
引言 医疗行业作为现代社会的关键基础设施,其能源消耗与环境影响正日益受到关注。随着全球"双碳"目标的推进和可持续发展理念的深入,智慧医疗能源事业线应运而生,致力于通过创新技术与管理方案,重构医疗领域的能源使用模式。这一事业线融合了能源管理、可持续发…...

YSYX学习记录(八)
C语言,练习0: 先创建一个文件夹,我用的是物理机: 安装build-essential 练习1: 我注释掉了 #include <stdio.h> 出现下面错误 在你的文本编辑器中打开ex1文件,随机修改或删除一部分,之后…...

自然语言处理——Transformer
自然语言处理——Transformer 自注意力机制多头注意力机制Transformer 虽然循环神经网络可以对具有序列特性的数据非常有效,它能挖掘数据中的时序信息以及语义信息,但是它有一个很大的缺陷——很难并行化。 我们可以考虑用CNN来替代RNN,但是…...
【Nginx】使用 Nginx+Lua 实现基于 IP 的访问频率限制
使用 NginxLua 实现基于 IP 的访问频率限制 在高并发场景下,限制某个 IP 的访问频率是非常重要的,可以有效防止恶意攻击或错误配置导致的服务宕机。以下是一个详细的实现方案,使用 Nginx 和 Lua 脚本结合 Redis 来实现基于 IP 的访问频率限制…...
uniapp 实现腾讯云IM群文件上传下载功能
UniApp 集成腾讯云IM实现群文件上传下载功能全攻略 一、功能背景与技术选型 在团队协作场景中,群文件共享是核心需求之一。本文将介绍如何基于腾讯云IMCOS,在uniapp中实现: 群内文件上传/下载文件元数据管理下载进度追踪跨平台文件预览 二…...

Ubuntu系统多网卡多相机IP设置方法
目录 1、硬件情况 2、如何设置网卡和相机IP 2.1 万兆网卡连接交换机,交换机再连相机 2.1.1 网卡设置 2.1.2 相机设置 2.3 万兆网卡直连相机 1、硬件情况 2个网卡n个相机 电脑系统信息,系统版本:Ubuntu22.04.5 LTS;内核版本…...
第八部分:阶段项目 6:构建 React 前端应用
现在,是时候将你学到的 React 基础知识付诸实践,构建一个简单的前端应用来模拟与后端 API 的交互了。在这个阶段,你可以先使用模拟数据,或者如果你的后端 API(阶段项目 5)已经搭建好,可以直接连…...
大数据治理的常见方式
大数据治理的常见方式 大数据治理是确保数据质量、安全性和可用性的系统性方法,以下是几种常见的治理方式: 1. 数据质量管理 核心方法: 数据校验:建立数据校验规则(格式、范围、一致性等)数据清洗&…...
WEB3全栈开发——面试专业技能点P4数据库
一、mysql2 原生驱动及其连接机制 概念介绍 mysql2 是 Node.js 环境中广泛使用的 MySQL 客户端库,基于 mysql 库改进而来,具有更好的性能、Promise 支持、流式查询、二进制数据处理能力等。 主要特点: 支持 Promise / async-await…...

DeepSeek越强,Kimi越慌?
被DeepSeek吊打的Kimi,还有多少人在用? 去年,月之暗面创始人杨植麟别提有多风光了。90后清华学霸,国产大模型六小虎之一,手握十几亿美金的融资。旗下的AI助手Kimi烧钱如流水,单月光是投流就花费2个亿。 疯…...