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

石家庄网站建设石家庄北京seo的排名优化

石家庄网站建设石家庄,北京seo的排名优化,小学校园网站建设简介,网页游戏制作培训文章目录 前言一、properties文件1.1properties格式介绍1.2读取项目resource/templates下面properties并处理中文乱码问题1.3读取本地properties并处理中文乱码问题1.4修改properties文件 二、XML文件2.1xml文件格式2.2读取xml文件2.3写xml文件 前言 在开发当中我们经常需要用… 文章目录 前言一、properties文件1.1properties格式介绍1.2读取项目resource/templates下面properties并处理中文乱码问题1.3读取本地properties并处理中文乱码问题1.4修改properties文件 二、XML文件2.1xml文件格式2.2读取xml文件2.3写xml文件 前言 在开发当中我们经常需要用到配置文件我们可以在配置文件中很方便的设置需要进行修改和配置的参数值有时候我们本地开发和生产环境中有些参数也不一样比如数据库IP和账号密码等、要读取的文件夹路径、日志备份的时间和周期等等有些人可能会说直接将这些值定义为final变量不久可以了吗这样的缺点是我们将项目部署到生产环境中时还要重新调整Java代码然后重新生成jar包或者war包而定义到配置文件中可以直接打开jar进行修改我们在配置文件中设置这些参数就很方便后续进行修改。 在java中常用的配置文件有properties、xml和txt本文就来介绍一下这三种配置文件的读写方法。 一、properties文件 1.1properties格式介绍 properties文件是一个文本文件以“键值”的方式书写一个属性的配置信息。 从上面的类结构图可以看出它继承了Hashtable并实现了Map接口 properties的属性配置键值前后的空格在解析时候会被忽略。 注 释前面加上#号 1.2读取项目resource/templates下面properties并处理中文乱码问题 读取properties文件需要注意的是如果读取出的值含有中文的话会出现乱码的问题需要再进行处理。 该properties文件放在项目resource/templates下面 代码如下 //读取properties资源文件public static String getProperties() {Properties properties new Properties();try {InputStream resourceAsStream SysSetParaEditController.class.getClassLoader().getResourceAsStream(getGKCX.properties);properties.load(resourceAsStream);String head properties.getProperty(head);String content properties.getProperty(content);String body properties.getProperty(body);String function properties.getProperty(function);String arg properties.getProperty(arg);String functionend properties.getProperty(functionend);String bodyend properties.getProperty(bodyend);String contentend properties.getProperty(contentend);System.out.println(head -- head);System.out.println(content -- content);System.out.println(body -- body);System.out.println(function -- function);System.out.println(arg -- arg);System.out.println(functionend -- functionend);System.out.println(bodyend -- bodyend);System.out.println(contentend -- contentend);resourceAsStream.close(); //关闭流}catch (IOException e) {e.printStackTrace();}//处理中文乱码String imgFolder properties.getProperty(imgFolder);try {imgFolder new String(imgFolder.getBytes(ISO-8859-1), GBK); // 处理中文乱码}catch (UnsupportedEncodingException e) {e.printStackTrace();}System.out.println(imgFolder);return imgFolder;}1.3读取本地properties并处理中文乱码问题 如果properties文件在本地的话可以这样进行读取 代码如下 //读取properties资源文件public static String getProperties() {Properties pro new Properties();int maxTotal 0;int maxIdel 0;String host null;int port 0;try {pro.load(new FileReader(D:\\sun\\getGKCX.properties));String imgFolder properties.getProperty(imgFolder);imgFolder new String(imgFolder.getBytes(ISO-8859-1), GBK); // 处理中文乱码} catch (IOException e) {e.printStackTrace();}System.out.println(imgFolder);return imgFolder;}1.4修改properties文件 public static void writePropertiesFile(String filename){Properties properties new Properties();try{//方法一使用FileWriter properties.setProperty(imgFolder, D:\\sun);//创建字节输出流/字符输出流构造方法中绑定要输出的目的地FileWriter fwnew FileWriter(D://a.txt);//使用Properties集合中的方法store把集合中的临时数据持久写入到硬盘中properties.store(fw, save data);//释放资源fw.close();//方法二使用OutputStream OutputStream outputStream new FileOutputStream(filename);properties.setProperty(imgFolder, D:\\sun\\img);properties.store(outputStream, author: sun);outputStream.close();}catch (IOException e){e.printStackTrace();}}二、XML文件 2.1xml文件格式 ML 指可扩展标记语言EXtensible Markup Language是一种标记语言很类似 HTML。 在XML中你可以拓展发明自己的标签XML没有预定义的标签XML允许创作者定义或设计自己的标签和文档结构 基本结构 XML文档的后缀名 .xml XML的第一行必须定义文档声明 在项目中经常见到的xml文件那就是pom.xml相信大家对这个一定都不陌生吧 还有mybatis使用的mybatis.xml ?xml version1.0 encodingUTF-8 ? !DOCTYPE configuration PUBLIC -//mybatis.org//DTD Config 3.0//EN http://mybatis.org/dtd/mybatis-3-config.dtd configuration!--environments defaultdevelopmentenvironment iddevelopmenttransactionManager typeJDBC/dataSource typePOOLEDproperty namedriver valuecom.mysql.jdbc.Driver/property nameurl valuejdbc:mysql://127.0.0.1/table?useUnicodetrueamp;characterEncodingutf-8amp;allowMultiQueriestrueamp;useSSLfalseamp;severTimezoneGMT%2B8/property nameusername valueroot/property namepassword value123456//dataSource/environment/environments--mappersmapper resourcecom/sun/server/mapper/xml/TScdLogMapper.xml/mapper resourcecom/sun/server/mapper/xml/TScdOperateMapper.xml/mapper resourcecom/sun/server/mapper/xml/TScdOperatePartsMapper.xml/mapper resourcecom/sun/server/mapper/xml/TSysParainfoMapper.xml//mappers /configuration2.2读取xml文件 代码如下示例 public static void readPropertiesFileFromXML(String filename){Properties properties new Properties();try{InputStream inputStream new FileInputStream(filename);properties.loadFromXML(inputStream);inputStream.close();}catch (IOException e){e.printStackTrace();}String imgFolder properties.getProperty(imgFolder);; //XML中的中文不用处理乱码正常显示}2.3写xml文件 代码如下示例 //写资源文件到XML文件含中文 public static void writePropertiesFileToXML(String filename){Properties properties new Properties();try{OutputStream outputStream new FileOutputStream(filename);properties.setProperty(imgFolder, D:\\sun\\img);properties.storeToXML(outputStream, author: sun);outputStream.close();}catch (IOException e){e.printStackTrace();}}
http://www.pierceye.com/news/162565/

相关文章:

  • 个人域名 公司网站百度推广和网站建设
  • 哪里有做网站服务抖音开放平台是什么
  • 公司网站上传不了图片建设网站条件
  • 精美公司网站源码婚礼策划网站设计
  • 线上设计师网站网络维护是什么意思
  • 培训网站建设阿里云如何建设网站
  • 手机网站列表模板做一钓鱼网站吗
  • 太原网站建设方案策划请问有重庆有做网站吗
  • 网站备案购买语音网站怎么做
  • ftp上传文件到网站深圳成品网站超市
  • 网站开发时app打开很慢建设网站还要云服务器吗
  • 网站设计方案应该怎么做网站自适应开发
  • 徐州手机网站设计青龙县建设局网站
  • 罗湖网站建设费用帮忙做文档的网站
  • 如何在720云网站做全景视频域名注册网站查询工具
  • 网站定制开发流程和功能wordpress怎么看访问
  • 浙江省互联网建设网站python开发手机网站开发
  • 做网站需要多少钱一年动漫制作技术是学什么
  • 刘洋网站建设 够完美保卫处网站建设
  • 个人怎么申请营业执照北京朝阳区优化
  • 免费的舆情网站不用下载直接打开江西城乡建设网站
  • 那些网站是做金融行业网站主目录权限配置
  • 本地网站做不大wordpress 安全设置
  • 宁波教育平台网站建设广告行业怎么找客户
  • php企业网站开发实验总结商城网站建设模板
  • 单词优化和整站优化建设银行的网站特点
  • 厦门淘宝网站设计公司wordpress大前端dux5.2
  • 淮南网站seo网络信息发布平台
  • 网站自己做流量如何查询网站被百度收录情况
  • 网络营销网站源码做网站中怎么设置单张图片