特殊文件
属性文件:属性文件的内容都是一些键值对信息,每一行都是键值对,后缀一般都是.properties结尾的。#注释
XML文件:注释<!-- -->,一般用于存储用户更加复杂的信息。作为系统的配置文件。
学习特殊文件:了解他们的特点、作用。学习使用程序读取里边的数据。学习使用程序把数据存储到这些文件中。
使用Map集合下的properties
读取
是一个Map集合(键值对集合),但是我们一般不会当成集合使用。
Properties是用来代表属性文件的,通过Properties可以读写属性文件里的内容。
user.properties
存储
修改
XML文件
XML(Extensible Markup Language可扩展标记语言),可扩展指的是标签可以自定义。
特点:
1.<>称为标签,一般成对出现。
2.标签可以自定义,但是要正确嵌套。
3.只能有一个根标签。
4.标签可以有属性。
5.后缀写成.xml
格式:
作用和应用场景
本质是一种数据格式,可以存储复杂的数据结构和数据关系.
应用场景:经常用来做系统的配置文件;或者作为一种特殊的数据结构,在网络中传播。
解析XML文件
使用程序读取XML中的数据。程序员不需要自己写IO流来解析,难度太大。
使用框架:Dom4j,他的解析方法是一层一层的,先拿外边,再拿里边。
getTextTrim 去除文本去除前后空格。
写入XML文件(少用)
不建议使用Dom4j,推荐直接把程序里的数据使用append拼接成XML文件,然后使用IO流写出去。
约束XML文件的书写
就是限制XML文件只能按照某种格式进行书写。
约束文档(了解)
专门用来限制XML的书写格式。分类:DTD文档、Schema文档。