专业做数据的网站有哪些crm系统分为哪三类
news/
2025/9/28 10:02:08/
文章来源:
专业做数据的网站有哪些,crm系统分为哪三类,wordpress付费播放器,怎样建设网站卖东西Java中读写资源文件最重要的类是Properties1) 资源文件要求如下:1、properties文件是一个文本文件2、properties文件的语法有两种#xff0c;一种是注释#xff0c;一种属性配置。注 释#xff1a;前面加上#号属性配置#xff1a;以“键值”的方式书写一个属性的配置信息…Java中读写资源文件最重要的类是Properties1) 资源文件要求如下:1、properties文件是一个文本文件2、properties文件的语法有两种一种是注释一种属性配置。注 释前面加上#号属性配置以“键值”的方式书写一个属性的配置信息。3、properties文件的一个属性配置信息值可以换行但键不可以换行。值换行用“\”表示。4、properties的属性配置键值前后的空格在解析时候会被忽略。5、properties文件可以只有键而没有值。也可以仅有键和等号而没有值但无论如何一个属性配置不能没有键。eg:正确的资源文件格式为2) 功能大致如下1. 读写Properties文件2. 读写XML文件3. 不仅可以读写上述两类文件还可以读写其它格式文件如txt等只要符合keyvalue格式即可.Properties能读取以key,value存储的任何格式文件看一下他的类结构就知道为什么了从上面的类结构图可以看出它继承了Hashtable并实现了Map接口3)代码演示1 packagecom.ifly.myhome.test;23 importjava.io.File;4 importjava.io.FileInputStream;5 importjava.io.FileOutputStream;6 importjava.io.IOException;7 importjava.io.InputStream;8 importjava.io.OutputStream;9 importjava.io.UnsupportedEncodingException;10 importjava.util.Properties;1112 public classPropertiesMyTest13 {1415 public static voidmain(String[] args)16 {1718 String readfile e: File.separator readfile.properties;19 String writefile e: File.separator writefile.properties;20 String readxmlfile e: File.separator readxmlfile.xml;21 String writexmlfile e: File.separator writexmlfile.xml;22 String readtxtfile e: File.separator readtxtfile.txt;23 String writetxtfile e: File.separator writetxtfile.txt;2425 readPropertiesFile(readfile); //读取properties文件26 writePropertiesFile(writefile); //写properties文件27 readPropertiesFileFromXML(readxmlfile); //读取XML文件28 writePropertiesFileToXML(writexmlfile); //写XML文件29 readPropertiesFile(readtxtfile); //读取txt文件30 writePropertiesFile(writetxtfile); //写txt文件31 }3233 //读取资源文件,并处理中文乱码34 public static voidreadPropertiesFile(String filename)35 {36 Properties properties newProperties();37 try38 {39 InputStream inputStream newFileInputStream(filename);40 properties.load(inputStream);41 inputStream.close(); //关闭流42 }43 catch(IOException e)44 {45 e.printStackTrace();46 }47 String username properties.getProperty(username);48 String passsword properties.getProperty(password);49 String chinese properties.getProperty(chinese);50 try51 {52 chinese new String(chinese.getBytes(ISO-8859-1), GBK); //处理中文乱码53 }54 catch(UnsupportedEncodingException e)55 {56 e.printStackTrace();57 }58 System.out.println(username);59 System.out.println(passsword);60 System.out.println(chinese);61 }6263 //读取XML文件,并处理中文乱码64 public static voidreadPropertiesFileFromXML(String filename)65 {66 Properties properties newProperties();67 try68 {69 InputStream inputStream newFileInputStream(filename);70 properties.loadFromXML(inputStream);71 inputStream.close();72 }73 catch(IOException e)74 {75 e.printStackTrace();76 }77 String username properties.getProperty(username);78 String passsword properties.getProperty(password);79 String chinese properties.getProperty(chinese); //XML中的中文不用处理乱码正常显示80 System.out.println(username);81 System.out.println(passsword);82 System.out.println(chinese);83 }8485 //写资源文件含中文86 public static voidwritePropertiesFile(String filename)87 {88 Properties properties newProperties();89 try90 {91 OutputStream outputStream newFileOutputStream(filename);92 properties.setProperty(username, myname);93 properties.setProperty(password, mypassword);94 properties.setProperty(chinese, 中文);95 properties.store(outputStream, author: shixing_11sina.com);96 outputStream.close();97 }98 catch(IOException e)99 {100 e.printStackTrace();101 }102 }103104 //写资源文件到XML文件含中文105 public static voidwritePropertiesFileToXML(String filename)106 {107 Properties properties newProperties();108 try109 {110 OutputStream outputStream newFileOutputStream(filename);111 properties.setProperty(username, myname);112 properties.setProperty(password, mypassword);113 properties.setProperty(chinese, 中文);114 properties.storeToXML(outputStream, author: shixing_11sina.com);115 outputStream.close();116 }117 catch(IOException e)118 {119 e.printStackTrace();120 }121 }122123 }View Code运行本程序所需的资源文件我是放在E盘根目录如E:/readfile.properties1. readfile.propertiesusernamekhpasswordkhchinese谓语2. writefile.properties#author: shixing_11sina.com#Fri May 28 22:19:44 CST 2010passwordkhchinese\u8C13\u8BEDusernamekh3. readxmlfile.xmlmypassword中文myname4. writexmlfile.xmlkh中文kh5. readtxtfile.txtusernamekhpasswordkhchinese中文6. writetxtfile.txtpasswordkhchinese/u4E2D/u6587usernamekh4)Properties获取数据乱码解决1.原因Properties调用load(InputStream)时读取文件时使用的默认编码为ISO-8859-1当我们讲中文放入到properties文件中通过getProperty(key)获取值时取到得数据是ISO-8859-1格式的但是ISO-8859-1是不能识别中文的。2.解决方法通过getProperty()获取的数据data既然是ISO-8859-1编码的就通过data.getByte(“iso-8859-1”)获取获取使用new String(data.getByte(“iso-8859-1”),”UTF-8”)进行转换。当然properties文件的编码类型需要和new String(Byte[],charst)中的第二个参数的编码类型相同
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/920479.shtml
如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!