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…...

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

深入剖析AI大模型:大模型时代的 Prompt 工程全解析
今天聊的内容,我认为是AI开发里面非常重要的内容。它在AI开发里无处不在,当你对 AI 助手说 "用李白的风格写一首关于人工智能的诗",或者让翻译模型 "将这段合同翻译成商务日语" 时,输入的这句话就是 Prompt。…...

页面渲染流程与性能优化
页面渲染流程与性能优化详解(完整版) 一、现代浏览器渲染流程(详细说明) 1. 构建DOM树 浏览器接收到HTML文档后,会逐步解析并构建DOM(Document Object Model)树。具体过程如下: (…...

高危文件识别的常用算法:原理、应用与企业场景
高危文件识别的常用算法:原理、应用与企业场景 高危文件识别旨在检测可能导致安全威胁的文件,如包含恶意代码、敏感数据或欺诈内容的文档,在企业协同办公环境中(如Teams、Google Workspace)尤为重要。结合大模型技术&…...

相机从app启动流程
一、流程框架图 二、具体流程分析 1、得到cameralist和对应的静态信息 目录如下: 重点代码分析: 启动相机前,先要通过getCameraIdList获取camera的个数以及id,然后可以通过getCameraCharacteristics获取对应id camera的capabilities(静态信息)进行一些openCamera前的…...

html-<abbr> 缩写或首字母缩略词
定义与作用 <abbr> 标签用于表示缩写或首字母缩略词,它可以帮助用户更好地理解缩写的含义,尤其是对于那些不熟悉该缩写的用户。 title 属性的内容提供了缩写的详细说明。当用户将鼠标悬停在缩写上时,会显示一个提示框。 示例&#x…...

初学 pytest 记录
安装 pip install pytest用例可以是函数也可以是类中的方法 def test_func():print()class TestAdd: # def __init__(self): 在 pytest 中不可以使用__init__方法 # self.cc 12345 pytest.mark.api def test_str(self):res add(1, 2)assert res 12def test_int(self):r…...
iOS性能调优实战:借助克魔(KeyMob)与常用工具深度洞察App瓶颈
在日常iOS开发过程中,性能问题往往是最令人头疼的一类Bug。尤其是在App上线前的压测阶段或是处理用户反馈的高发期,开发者往往需要面对卡顿、崩溃、能耗异常、日志混乱等一系列问题。这些问题表面上看似偶发,但背后往往隐藏着系统资源调度不当…...

代码规范和架构【立芯理论一】(2025.06.08)
1、代码规范的目标 代码简洁精炼、美观,可持续性好高效率高复用,可移植性好高内聚,低耦合没有冗余规范性,代码有规可循,可以看出自己当时的思考过程特殊排版,特殊语法,特殊指令,必须…...
WebRTC从入门到实践 - 零基础教程
WebRTC从入门到实践 - 零基础教程 目录 WebRTC简介 基础概念 工作原理 开发环境搭建 基础实践 三个实战案例 常见问题解答 1. WebRTC简介 1.1 什么是WebRTC? WebRTC(Web Real-Time Communication)是一个支持网页浏览器进行实时语音…...

springboot 日志类切面,接口成功记录日志,失败不记录
springboot 日志类切面,接口成功记录日志,失败不记录 自定义一个注解方法 import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target;/***…...