Java中System.getProperty()的取值问题

本文介绍了如何通过Java代码获取系统属性,包括Java运行时环境版本、供应商信息、类路径、操作系统名称、架构、版本等关键信息。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

java.version

Java 运行时环境版本

java.vendor

Java 运行时环境供应商

java.vendor.url

Java 供应商的 URL

java.home

Java 安装目录

java.vm.specification.version

Java 虚拟机规范版本

java.vm.specification.vendor

Java 虚拟机规范供应商

java.vm.specification.name

Java 虚拟机规范名称

java.vm.version

Java 虚拟机实现版本

java.vm.vendor

Java 虚拟机实现供应商

java.vm.name

Java 虚拟机实现名称

java.specification.version

Java 运行时环境规范版本

java.specification.vendor

Java 运行时环境规范供应商

java.specification.name

Java 运行时环境规范名称

java.class.version

Java 类格式版本号

java.class.path

Java 类路径

java.library.path

加载库时搜索的路径列表

java.io.tmpdir

默认的临时文件路径

java.compiler

要使用的 JIT 编译器的名称

java.ext.dirs

一个或多个扩展目录的路径

os.name

操作系统的名称

os.arch

操作系统的架构

os.version

操作系统的版本

file.separator

文件分隔符(在 UNIX 系统中是“/”)

path.separator

路径分隔符(在 UNIX 系统中是“:”)

line.separator

行分隔符(在 UNIX 系统中是“/n”)

user.name

用户的账户名称

user.home

用户的主目录

user.dir

用户的当前工作目录

 

获取的代码示例:

[java]  view plain copy
  1. public class SystemProperty {  
  2.     public static void main(String args[]) {     
  3.     System.out.println("java_vendor:" + System.getProperty("java.vendor"));     
  4.     System.out.println("java_vendor_url:"     
  5.              + System.getProperty("java.vendor.url"));     
  6.     System.out.println("java_home:" + System.getProperty("java.home"));     
  7.     System.out.println("java_class_version:"     
  8.              + System.getProperty("java.class.version"));     
  9.     System.out.println("java_class_path:"     
  10.             + System.getProperty("java.class.path"));     
  11.     System.out.println("os_name:" + System.getProperty("os.name"));     
  12.     System.out.println("os_arch:" + System.getProperty("os.arch"));     
  13.     System.out.println("os_version:" + System.getProperty("os.version"));     
  14.     System.out.println("user_name:" + System.getProperty("user.name"));     
  15.     System.out.println("user_home:" + System.getProperty("user.home"));     
  16.     System.out.println("user_dir:" + System.getProperty("user.dir"));     
  17.     System.out.println("java_vm_specification_version:"     
  18.             + System.getProperty("java.vm.specification.version"));     
  19.     System.out.println("java_vm_specification_vendor:"     
  20.             + System.getProperty("java.vm.specification.vendor"));     
  21.     System.out.println("java_vm_specification_name:"     
  22.             + System.getProperty("java.vm.specification.name"));     
  23.     System.out.println("java_vm_version:"     
  24.             + System.getProperty("java.vm.version"));     
  25.     System.out.println("java_vm_vendor:"     
  26.             + System.getProperty("java.vm.vendor"));     
  27.     System.out     
  28.             .println("java_vm_name:" + System.getProperty("java.vm.name"));     
  29.     System.out.println("java_ext_dirs:"     
  30.             + System.getProperty("java.ext.dirs"));     
  31.     System.out.println("file_separator:"     
  32.             + System.getProperty("file.separator"));     
  33.     System.out.println("path_separator:"     
  34.             + System.getProperty("path.separator"));     
  35.     System.out.println("line_separator:"     
  36.             + System.getProperty("line.separator"));     
  37. }     

原文出处:http://blog.youkuaiyun.com/kongqz/article/details/3987198

package com.example.controller; import cn.hutool.core.io.FileUtil; import com.example.common.Result; import com.example.exception.CustomException; import jakarta.servlet.ServletOutputStream; import jakarta.servlet.http.HttpServletResponse; import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; import java.io.IOException; import java.net.URLEncoder; import java.nio.charset.StandardCharsets; //处理文件上传和下载的相关接口 @RestController @RequestMapping("/files") public class FileController { //文件上传 @PostMapping("/upload") public Result upload(@RequestParam("file") MultipartFile file) throws Exception { String filePath=System.getProperty("user.dir")+"/files/";//获取当前项目的根路径(xm-pro的绝对路径E:\Item\代码\xm-pro\springboot) //找到文件位置 if(FileUtil.isDirectory(filePath)){ FileUtil.mkdir(filePath); } byte[] bytes= file.getBytes(); String fileName=System.currentTimeMillis()+"_"+file.getOriginalFilename();//文件的原始名称,加唯一数 //写入文件 FileUtil.writeBytes(bytes, filePath+fileName); String url="http://localhost:8080/files/download/"+fileName; return Result.success(url); } //文件下载 //下载路径 @GetMapping("/download/{fileName}")//通过浏览器直接访问用get public void download(@PathVariable String fileName,HttpServletResponse response) throws CustomException, IOException {//流的方式下载不需要返回对象 String filePath=System.getProperty("user.dir")+"/files/";//获取当前项目的根路径(xm-pro的绝对路径E:\Item\代码\xm-pro\springboot) //找到文件位置 String realPath=filePath+fileName;//E:\Item\代码\xm-pro\files\图片名称 boolean exist=FileUtil.exist(realPath); if(!exist){ throw new CustomException("文件不存在"); } //读取文件的字节流 byte[] bytes= FileUtil.readBytes(realPath); ServletOutputStream os=response.getOutputStream(); //输出流对象把文件写到客户端 os.write(bytes); os.flush(); os.close(); } } <el-form-item label="头像" prop="avatar"> <el-upload action="http://localhost:8080/files/upload" :Headers="{token:data.user.token}" :on-success="handleFileSuccess" list-type="picture" > <el-button type="primary">上传头像</el-button> </el-upload> </el-form-item> const handleFileSuccess=(res)=>{ data.form.avatar=res.data } 为什么前端点击上传头像时,数据库里面avatar里面没有添加成功url值
最新发布
03-17
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值