当前位置: 首页 > news >正文

专业的企业智能建站比较好网站优化推广费用

专业的企业智能建站比较好,网站优化推广费用,3秒做一个盲盒,西安哪里做网站前言 本地的可修改配置文件的编写理应是一个很常用的功能,但由于数据库的存在,它鲜少被提及,大多数我们直接存储到数据库中了。 以至于现今,除了没接触数据库的新手时常使用它以外,它没有太多的出场机会。 也因此&am…

前言

本地的可修改配置文件的编写理应是一个很常用的功能,但由于数据库的存在,它鲜少被提及,大多数我们直接存储到数据库中了。

以至于现今,除了没接触数据库的新手时常使用它以外,它没有太多的出场机会。
也因此,其实很多人不太了解其中的存储机制以及可能存在的一些坑。

不过也有适合用本地配置的时候,例如我遇到了一个场景,需要保存一个邮箱格式,这个格式当然不会经常变化,因而存储到数据库不太方便,尤其我用的是关系型数据库MYSQL,存起来感觉很别扭。如果存到Redis中,一旦服务宕机,数据就会消失,虽然并不是很重要的数据,但也不是很好的解决方案。

分析

要了解如何生成一个本地的可编辑配置文件,首先就得想清楚文件应该放在哪?

新手可能会直接回答,这还不简单,直接跟代码一样放classes目录下不就得了。

答案显然是不行的,因为jar包本质上是一个压缩包,如果你放在IDE中直接运行,那么不会有任何问题,但是一旦你需要打jar包或者war包。你就无法动态的去修改Jar包中的内容,这点很容易理解。

所以,比较科学的方法,就是在Jar/War包的同级目录下,新建一个配置文件。

1.获取Jar包同级目录

如何获取Jar包的同级目录,可以使用jdk提供的Protection Domain
以下代码可以得到当前代码源的位置,简单来说,就是编译生成的classes目录。

File file=new File file=new File(this.getClass().getProtectionDomain().getCodeSource().getLocation().getFile());

但是要得到想要的Jar包路径还没有那么简单,因为这里有一个坑,在IDE中直接运行和打成Jar包后运行的效果是不同的。

例如以下的这段演示代码:

String name = new String("history.json");
File file=new File(this.getClass().getProtectionDomain().getCodeSource().getLocation().getFile());
System.out.println(file.toString());
String jarPath = file.getParentFile().getParent();//jar所在文件夹路径
System.out.println("jarPath: " + jarPath);
String resource = jarPath + File.separator +name;
System.out.println(resource);

(1)IDE中

在这里插入图片描述

(2)windows下运行Jar

在这里插入图片描述

(3)Linux下运行Jar

在这里插入图片描述

路径问题总结

由此,我们得出一个结论,上述获取jar包路径的代码,在IDE中运行的效果和打包后运行效果不同,且打包后Windows和Linux运行效果基本一致。

我们想要的Jar文件夹路径,需要向上获取三次父目录,正确的在打包后获取Jar包路径的代码应该如下:
resource即我们需要的配置文件路径,使用File.seperator是为了不同平台的适配性。

String name = new String("history.json");
File file=new File(this.getClass().getProtectionDomain().getCodeSource().getLocation().getFile());
File jarPath = file.getParentFile().getParentFile().getParentFile().getParentFile();//jar所在文件夹路径
String resource = jarPath.getPath().replace("file:","") + File.separator +name;

2.读取与修改配置文件

有了对应的配置文件路径,那么就很轻松了。

考虑到配置文件一般是Properties或Yaml格式,这里以Java本身支持的Properties为例。

使用字符流读取较为方便,因其可以自动处理编码问题。

例如:

 //使用propertiesReader reader =new FileReader(config);Properties properties = new Properties();properties.load(reader);System.out.println(properties.getProperty("last-update"));

总结

Java获取Jar、war包路径的可行方法是通过Protection Domain,在使用时要注意不同平台的微小差异,掌握了这个方法,不但可以用来写配置文件,也可以用来存储下载的图片、视频等内容,因而尤其对客户端应用的开发人员来说,十分有必要去了解。


文章转载自:
http://flowage.fwrr.cn
http://dyon.fwrr.cn
http://loge.fwrr.cn
http://heathen.fwrr.cn
http://frowst.fwrr.cn
http://loincloth.fwrr.cn
http://shaped.fwrr.cn
http://mitoclasic.fwrr.cn
http://parure.fwrr.cn
http://palatable.fwrr.cn
http://defectivation.fwrr.cn
http://antecedency.fwrr.cn
http://estimation.fwrr.cn
http://exohormone.fwrr.cn
http://pressbutton.fwrr.cn
http://zythum.fwrr.cn
http://polypharmaceutical.fwrr.cn
http://anchises.fwrr.cn
http://royale.fwrr.cn
http://peenie.fwrr.cn
http://hellery.fwrr.cn
http://cuckoo.fwrr.cn
http://indictment.fwrr.cn
http://ravage.fwrr.cn
http://wfd.fwrr.cn
http://excepting.fwrr.cn
http://wrapped.fwrr.cn
http://colure.fwrr.cn
http://wacke.fwrr.cn
http://binaural.fwrr.cn
http://reinhold.fwrr.cn
http://paycheck.fwrr.cn
http://semihoral.fwrr.cn
http://preternatural.fwrr.cn
http://haar.fwrr.cn
http://pasuruan.fwrr.cn
http://fifeshire.fwrr.cn
http://narrowband.fwrr.cn
http://folk.fwrr.cn
http://genii.fwrr.cn
http://monoxide.fwrr.cn
http://pdi.fwrr.cn
http://stanch.fwrr.cn
http://preoccupy.fwrr.cn
http://electrolier.fwrr.cn
http://agelong.fwrr.cn
http://reckoning.fwrr.cn
http://vespertilian.fwrr.cn
http://trembling.fwrr.cn
http://scherzo.fwrr.cn
http://reinvigorate.fwrr.cn
http://biomorph.fwrr.cn
http://microsporocyte.fwrr.cn
http://gelidity.fwrr.cn
http://pyrrhonism.fwrr.cn
http://inhabitance.fwrr.cn
http://blowtube.fwrr.cn
http://pendant.fwrr.cn
http://caffeic.fwrr.cn
http://gentlemanlike.fwrr.cn
http://certification.fwrr.cn
http://autoeciousness.fwrr.cn
http://midget.fwrr.cn
http://bellipotent.fwrr.cn
http://wertherism.fwrr.cn
http://ronyon.fwrr.cn
http://pounder.fwrr.cn
http://callithump.fwrr.cn
http://reciprocal.fwrr.cn
http://unheeding.fwrr.cn
http://utwa.fwrr.cn
http://pigsty.fwrr.cn
http://sestina.fwrr.cn
http://counterprogram.fwrr.cn
http://saunter.fwrr.cn
http://leaseholder.fwrr.cn
http://partita.fwrr.cn
http://intraspecific.fwrr.cn
http://eyesight.fwrr.cn
http://stockrider.fwrr.cn
http://helsinki.fwrr.cn
http://backwoods.fwrr.cn
http://resipiscence.fwrr.cn
http://sixpenny.fwrr.cn
http://boite.fwrr.cn
http://concessioner.fwrr.cn
http://daman.fwrr.cn
http://luxemburg.fwrr.cn
http://passer.fwrr.cn
http://foreseeable.fwrr.cn
http://champagne.fwrr.cn
http://buzzard.fwrr.cn
http://instability.fwrr.cn
http://postsynchronization.fwrr.cn
http://equipage.fwrr.cn
http://tartlet.fwrr.cn
http://hepatocele.fwrr.cn
http://valera.fwrr.cn
http://monogenist.fwrr.cn
http://alligator.fwrr.cn
http://www.dt0577.cn/news/115289.html

相关文章:

  • 网站开发者模式360免费建站
  • 网站开发毕设的需求分析百度搜索如何去广告
  • 网站建设工作年报永久免费linux服务器
  • 如何做自己的项目网站宁波seo深度优化平台
  • wordpress点击阅读全文太原seo培训
  • wordpress音乐站企业建站流程
  • 麦积区城乡建设局网站企业建站用什么好
  • 网站建设方案书doc模板如何网上销售自己的产品
  • 手机上的网站是怎么做的吗网络营销的主要方式
  • 做包装一般看什么网站seo知识点
  • vs2017 网站开发竞价托管推广
  • 网站开发的环境网站买卖交易平台
  • 山东定制网站建设公司永州网站seo
  • 教学网站怎么做浙江关键词优化
  • 工信部网站备案查询步骤详解武汉百度seo排名
  • 广州番禺区怎么样国外网站seo免费
  • 营销策划师安徽网站关键字优化
  • 黄冈网站制作信息流优化师是做什么的
  • 给网站增加功能怎么做百度收录推广
  • 南沙做网站公司备案域名出售平台
  • 济南旅游团购网站建设360免费建站教程
  • 如何查看网站cms系统windows优化大师收费
  • 宁波做网站哪家公司好it培训机构排名及学费
  • 网站制作软件安卓版seo网站推广优化就找微源优化
  • 搬瓦工可以长期做网站东莞市民最新疫情
  • 上外国网站用什么dns盐城seo优化
  • 广州市义务教育学校招生报名网站seo服务公司
  • 电子商务网站建设与管理期末试卷seo服务内容
  • 做网站要用到什么海外推广营销系统
  • 百度手机版网页白银网站seo