Java获取服务器系统默认编码格式

大佬教的,做个笔记

//Spring管理类中获取requets.attributes
ServletRequestAttributes attrs = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
if (attrs == null) {
// throw new IllegalStateException("当前线程中不存在 Request 上下文");
}else{
//信息源
Properties properties = System.getProperties();
//获取真实项目路径('.../webapps' + '/images/testLog.txt')
String logRealPath = attrs.getRequest().getServletContext().getRealPath("/images/testLog.txt");
//开启流
OutputStream out=new FileOutputStream(logRealPath,true);
//拿到系统信息
Set<Map.Entry<Object, Object>> entries = properties.entrySet();
//打印到文件当中
for (Map.Entry entry:entries
) {
out.write(entry.getKey().toString().getBytes("UTF-8"));
out.write("-->".getBytes("UTF-8"));
out.write(entry.getValue().toString().getBytes("UTF-8"));
out.write("\n".getBytes("UTF-8"));
}

//关闭流
out.close();
}

//浏览器输入项目路径/images/testLog.txt查看
查找“file.encoding”


上一篇:drf 自带token学习记录


下一篇:Python Beautiful Soup 4 模块