Java系统属性工具类

标签: java system properties 工具类
23人阅读 评论(0) 收藏 举报
分类:

Java系统属性工具类


// 一共大约540行代码
// 共108个公开方法

import utils.print.Print;

import java.util.Properties;

/**
 * @author Created by 谭健 on 2018/4/16 0016. 星期一. 15:36.
 * © All Rights Reserved.
 */

public class SystemPropertieUtils {


    public static String getSunCpuIsalist() {
        return System.getProperty("sun.cpu.isalist");
    }

    public static String getSunDesktop() {
        return System.getProperty("sun.desktop");
    }

    public static String getSunIoUnicodeEncoding() {
        return System.getProperty("sun.io.unicode.encoding");
    }

    public static String getSunCpuEndian() {
        return System.getProperty("sun.cpu.endian");
    }

    public static String getJavaVendorUrlBug() {
        return System.getProperty("java.vendor.url.bug");
    }

    public static String getFileSeparator() {
        return System.getProperty("file.separator");
    }

    public static String getJavaVendor() {
        return System.getProperty("java.vendor");
    }

    public static String getSunBootClassPath() {
        return System.getProperty("sun.boot.class.path");
    }

    public static String getJavaExtDirs() {
        return System.getProperty("java.ext.dirs");
    }

    public static String getJavaVersion() {
        return System.getProperty("java.version");
    }

    public static String getJavaVmInfo() {
        return System.getProperty("java.vm.info");
    }

    public static String getAwtToolkit() {
        return System.getProperty("awt.toolkit");
    }

    public static String getUserLanguage() {
        return System.getProperty("user.language");
    }

    public static String getJavaSpecificationVendor() {
        return System.getProperty("java.specification.vendor");
    }

    public static String getSunJavaCommand() {
        return System.getProperty("sun.java.command");
    }

    public static String getJavaHome() {
        return System.getProperty("java.home");
    }

    public static String getSunArchDataModel() {
        return System.getProperty("sun.arch.data.model");
    }

    public static String getJavaVmSpecificationVersion() {
        return System.getProperty("java.vm.specification.version");
    }

    public static String getJavaClassPath() {
        return System.getProperty("java.class.path");
    }

    public static String getUserName() {
        return System.getProperty("user.name");
    }

    public static String getFileEncoding() {
        return System.getProperty("file.encoding");
    }

    public static String getJavaSpecificationVersion() {
        return System.getProperty("java.specification.version");
    }

    public static String getJavaAwtPrinterjob() {
        return System.getProperty("java.awt.printerjob");
    }

    public static String getUserTimezone() {
        return System.getProperty("user.timezone");
    }

    public static String getUserHome() {
        return System.getProperty("user.home");
    }

    public static String getOsVersion() {
        return System.getProperty("os.version");
    }

    public static String getSunManagementCompiler() {
        return System.getProperty("sun.management.compiler");
    }

    public static String getJavaSpecificationName() {
        return System.getProperty("java.specification.name");
    }

    public static String getJavaClassVersion() {
        return System.getProperty("java.class.version");
    }

    public static String getJavaLibraryPath() {
        return System.getProperty("java.library.path");
    }

    public static String getSunJnuEncoding() {
        return System.getProperty("sun.jnu.encoding");
    }

    public static String getOsName() {
        return System.getProperty("os.name");
    }

    public static String getUserVariant() {
        return System.getProperty("user.variant");
    }

    public static String getJavaVmSpecificationVendor() {
        return System.getProperty("java.vm.specification.vendor");
    }

    public static String getJavaIoTmpdir() {
        return System.getProperty("java.io.tmpdir");
    }

    public static String getLineSeparator() {
        return System.getProperty("line.separator");
    }

    public static String getJavaEndorsedDirs() {
        return System.getProperty("java.endorsed.dirs");
    }

    public static String getOsArch() {
        return System.getProperty("os.arch");
    }

    public static String getJavaAwtGraphicsenv() {
        return System.getProperty("java.awt.graphicsenv");
    }

    public static String getJavaRuntimeVersion() {
        return System.getProperty("java.runtime.version");
    }

    public static String getJavaVmSpecificationName() {
        return System.getProperty("java.vm.specification.name");
    }

    public static String getUserDir() {
        return System.getProperty("user.dir");
    }

    public static String getUserCountry() {
        return System.getProperty("user.country");
    }

    public static String getUserScript() {
        return System.getProperty("user.script");
    }

    public static String getSunJavaLauncher() {
        return System.getProperty("sun.java.launcher");
    }

    public static String getSunOsPatchLevel() {
        return System.getProperty("sun.os.patch.level");
    }

    public static String getJavaVmName() {
        return System.getProperty("java.vm.name");
    }

    public static String getFileEncodingPkg() {
        return System.getProperty("file.encoding.pkg");
    }

    public static String getPathSeparator() {
        return System.getProperty("path.separator");
    }

    public static String getJavaVmVendor() {
        return System.getProperty("java.vm.vendor");
    }

    public static String getJavaVendorUrl() {
        return System.getProperty("java.vendor.url");
    }

    public static String getSunBootLibraryPath() {
        return System.getProperty("sun.boot.library.path");
    }

    public static String getJavaVmVersion() {
        return System.getProperty("java.vm.version");
    }

    public static String getJavaRuntimeName() {
        return System.getProperty("java.runtime.name");
    }


    public static void setSunCpuIsalist(String value) {
        System.setProperty("sun.cpu.isalist", value);
    }

    public static void setSunDesktop(String value) {
        System.setProperty("sun.desktop", value);
    }

    public static void setSunIoUnicodeEncoding(String value) {
        System.setProperty("sun.io.unicode.encoding", value);
    }

    public static void setSunCpuEndian(String value) {
        System.setProperty("sun.cpu.endian", value);
    }

    public static void setJavaVendorUrlBug(String value) {
        System.setProperty("java.vendor.url.bug", value);
    }

    public static void setFileSeparator(String value) {
        System.setProperty("file.separator", value);
    }

    public static void setJavaVendor(String value) {
        System.setProperty("java.vendor", value);
    }

    public static void setSunBootClassPath(String value) {
        System.setProperty("sun.boot.class.path", value);
    }

    public static void setJavaExtDirs(String value) {
        System.setProperty("java.ext.dirs", value);
    }

    public static void setJavaVersion(String value) {
        System.setProperty("java.version", value);
    }

    public static void setJavaVmInfo(String value) {
        System.setProperty("java.vm.info", value);
    }

    public static void setAwtToolkit(String value) {
        System.setProperty("awt.toolkit", value);
    }

    public static void setUserLanguage(String value) {
        System.setProperty("user.language", value);
    }

    public static void setJavaSpecificationVendor(String value) {
        System.setProperty("java.specification.vendor", value);
    }

    public static void setSunJavaCommand(String value) {
        System.setProperty("sun.java.command", value);
    }

    public static void setJavaHome(String value) {
        System.setProperty("java.home", value);
    }

    public static void setSunArchDataModel(String value) {
        System.setProperty("sun.arch.data.model", value);
    }

    public static void setJavaVmSpecificationVersion(String value) {
        System.setProperty("java.vm.specification.version", value);
    }

    public static void setJavaClassPath(String value) {
        System.setProperty("java.class.path", value);
    }

    public static void setUserName(String value) {
        System.setProperty("user.name", value);
    }

    public static void setFileEncoding(String value) {
        System.setProperty("file.encoding", value);
    }

    public static void setJavaSpecificationVersion(String value) {
        System.setProperty("java.specification.version", value);
    }

    public static void setJavaAwtPrinterjob(String value) {
        System.setProperty("java.awt.printerjob", value);
    }

    public static void setUserTimezone(String value) {
        System.setProperty("user.timezone", value);
    }

    public static void setUserHome(String value) {
        System.setProperty("user.home", value);
    }

    public static void setOsVersion(String value) {
        System.setProperty("os.version", value);
    }

    public static void setSunManagementCompiler(String value) {
        System.setProperty("sun.management.compiler", value);
    }

    public static void setJavaSpecificationName(String value) {
        System.setProperty("java.specification.name", value);
    }

    public static void setJavaClassVersion(String value) {
        System.setProperty("java.class.version", value);
    }

    public static void setJbossModulesSystemPkgs(String value) {
        System.setProperty("jboss.modules.system.pkgs", value);
    }

    public static void setJavaLibraryPath(String value) {
        System.setProperty("java.library.path", value);
    }

    public static void setSunJnuEncoding(String value) {
        System.setProperty("sun.jnu.encoding", value);
    }

    public static void setOsName(String value) {
        System.setProperty("os.name", value);
    }

    public static void setUserVariant(String value) {
        System.setProperty("user.variant", value);
    }

    public static void setJavaVmSpecificationVendor(String value) {
        System.setProperty("java.vm.specification.vendor", value);
    }

    public static void setJavaIoTmpdir(String value) {
        System.setProperty("java.io.tmpdir", value);
    }

    public static void setLineSeparator(String value) {
        System.setProperty("line.separator", value);
    }

    public static void setJavaEndorsedDirs(String value) {
        System.setProperty("java.endorsed.dirs", value);
    }

    public static void setOsArch(String value) {
        System.setProperty("os.arch", value);
    }

    public static void setJavaAwtGraphicsenv(String value) {
        System.setProperty("java.awt.graphicsenv", value);
    }

    public static void setJavaRuntimeVersion(String value) {
        System.setProperty("java.runtime.version", value);
    }

    public static void setJavaVmSpecificationName(String value) {
        System.setProperty("java.vm.specification.name", value);
    }

    public static void setUserDir(String value) {
        System.setProperty("user.dir", value);
    }

    public static void setUserCountry(String value) {
        System.setProperty("user.country", value);
    }

    public static void setUserScript(String value) {
        System.setProperty("user.script", value);
    }

    public static void setSunJavaLauncher(String value) {
        System.setProperty("sun.java.launcher", value);
    }

    public static void setSunOsPatchLevel(String value) {
        System.setProperty("sun.os.patch.level", value);
    }

    public static void setJavaVmName(String value) {
        System.setProperty("java.vm.name", value);
    }

    public static void setFileEncodingPkg(String value) {
        System.setProperty("file.encoding.pkg", value);
    }

    public static void setPathSeparator(String value) {
        System.setProperty("path.separator", value);
    }

    public static void setJavaVmVendor(String value) {
        System.setProperty("java.vm.vendor", value);
    }

    public static void setJavaVendorUrl(String value) {
        System.setProperty("java.vendor.url", value);
    }

    public static void setSunBootLibraryPath(String value) {
        System.setProperty("sun.boot.library.path", value);
    }

    public static void setJavaVmVersion(String value) {
        System.setProperty("java.vm.version", value);
    }

    public static void setJavaRuntimeName(String value) {
        System.setProperty("java.runtime.name", value);
    }

    public static void main(String[] args) {
        fast();

    }

    private static void print() {
        Print.echo(getSunCpuIsalist());
        Print.echo(getSunDesktop());
        Print.echo(getSunIoUnicodeEncoding());
        Print.echo(getSunCpuEndian());
        Print.echo(getJavaVendorUrlBug());
        Print.echo(getFileSeparator());
        Print.echo(getJavaVendor());
        Print.echo(getSunBootClassPath());
        Print.echo(getJavaExtDirs());
        Print.echo(getJavaVersion());
        Print.echo(getJavaVmInfo());
        Print.echo(getAwtToolkit());
        Print.echo(getUserLanguage());
        Print.echo(getJavaSpecificationVendor());
        Print.echo(getSunJavaCommand());
        Print.echo(getJavaHome());
        Print.echo(getSunArchDataModel());
        Print.echo(getJavaVmSpecificationVersion());
        Print.echo(getJavaClassPath());
        Print.echo(getUserName());
        Print.echo(getFileEncoding());
        Print.echo(getJavaSpecificationVersion());
        Print.echo(getJavaAwtPrinterjob());
        Print.echo(getUserTimezone());
        Print.echo(getUserHome());
        Print.echo(getOsVersion());
        Print.echo(getSunManagementCompiler());
        Print.echo(getJavaSpecificationName());
        Print.echo(getJavaClassVersion());
        Print.echo(getJavaLibraryPath());
        Print.echo(getSunJnuEncoding());
        Print.echo(getOsName());
        Print.echo(getUserVariant());
        Print.echo(getJavaVmSpecificationVendor());
        Print.echo(getJavaIoTmpdir());
        Print.echo(getLineSeparator());
        Print.echo(getJavaEndorsedDirs());
        Print.echo(getOsArch());
        Print.echo(getJavaAwtGraphicsenv());
        Print.echo(getJavaRuntimeVersion());
        Print.echo(getJavaVmSpecificationName());
        Print.echo(getUserDir());
        Print.echo(getUserCountry());
        Print.echo(getUserScript());
        Print.echo(getSunJavaLauncher());
        Print.echo(getSunOsPatchLevel());
        Print.echo(getJavaVmName());
        Print.echo(getFileEncodingPkg());
        Print.echo(getPathSeparator());
        Print.echo(getJavaVmVendor());
        Print.echo(getJavaVendorUrl());
        Print.echo(getSunBootLibraryPath());
        Print.echo(getJavaVmVersion());
        Print.echo(getJavaRuntimeName());
    }

    private static void fast() {
        Properties properties = System.getProperties();
        properties.forEach((o, o2) -> {

            String var = o.toString();
            char[] vars = var.toCharArray();
            String varName = "";
            for (int i = 0; i < vars.length; i++) {
                if (i == 0) {
                    varName += String.valueOf(vars[i]).toUpperCase();
                    continue;
                }
                if (vars[i] == '.') continue;
                if (i > 0 && vars[i - 1] == '.') {
                    varName += String.valueOf(vars[i]).toUpperCase();
                    continue;
                }
                varName += String.valueOf(vars[i]);

            }

            // 方法太多,懒的写,自动生成方法

            //  Print.echo(varName);
            //  Print.echo("public static String get" + varName + "(){ return System.getProperty(\"" + var + "\");}");
            //  Print.echo("Print.echo(get" + varName + "());");
            //  Print.echo("public static void set" + varName + "(String value){ System.setProperty(\"" + var + "\",value);}");
        });
    }
}
查看评论

用C#实现封装

本课程主要讲解了C#中属性的封装,方法的应用,构造函数的重载,以及值传递和引用传递的区别。在学习本课程之前需要掌握一定的基础知识。
  • 2017年07月23日 16:27

java系统属性

系统属性是指与用户程序相关的操作系统配置信息以及软件信息。通常与用户程序相关的属性关键字包括:  ●file.separator:文件分隔符,Windows环境下为“",Unix环境下为“/”;  ●...
  • babydavic
  • babydavic
  • 2007-08-23 11:17:00
  • 6258

java 设置系统属性

设置系统属性常用:System.setProperty("password","wp"); 在eclipse中可以通过下面方式设置系统属性: Runas--> Run configuratio...
  • qilixiang012
  • qilixiang012
  • 2014-07-07 21:11:12
  • 2523

使用java获取系统属性

使用java获取操作系统环境变量与系统属性
  • liupq66
  • liupq66
  • 2016-07-28 11:41:30
  • 755

通过spring设置java系统属性

在做RMI的时候需要如遇到rmi所在服务是多网卡时,需要对系统属性java.rmi.server.hostname进行设置 ,以前我们会扩展spring的listener public clas...
  • buyaore_wo
  • buyaore_wo
  • 2012-10-09 16:58:25
  • 2472

Java学习篇之---环境变量和系统属性

Java学习篇之---环境变量和系统属性 一、前言:         Java环境变量(getenv)与系统属性(getProperties)         getenv是获取系统的环境变量,对于w...
  • A_little_e
  • A_little_e
  • 2016-05-13 16:12:05
  • 842

java系统属性取得

     //系统属性     String   javaVersion     =   System.getProperty("java.version");     String   javaVe...
  • popkiler
  • popkiler
  • 2007-09-03 17:17:00
  • 537

通过命令行设置一个系统属性的值

可以在通过在运行程序时在java后使用-D参数来设置一个系统属性值:java -Dtesge.home="e:/home" TestApp在程序中获得方法为: String dir = System....
  • tesge
  • tesge
  • 2005-03-02 14:22:00
  • 1966

Java之系统属性

当前程序目录-通过调用System.getProperty("user.dir")来获得。 文件分隔符-通过java.io.File.separator或System.getProperty("fi...
  • u012643122
  • u012643122
  • 2014-08-13 18:55:05
  • 1611

Java -D 配置系统属性

原文地址:http://blog.csdn.net/wo541075754/article/details/55051693 我们都知道在启动tomcat或直接执行Java命令的时候可以通过参数-...
  • tanga842428
  • tanga842428
  • 2017-07-15 10:06:34
  • 250
    个人资料
    专栏达人 持之以恒
    等级:
    访问量: 19万+
    积分: 3465
    排名: 1万+
    个人说明
    博客专栏