`

配置文件

阅读更多

[color=indigo]

   
this.getClass().getClassLoader().getResourceAsStream(String path);
System.getProperty("user.dir");  //当前路径
this.getClass().getClassLoader().getResource("\\").getPath();
this.getClass().getClassLoader().getResource(".").getPath();
this.getClass().getClassLoader().getResource("").getPath();
this.getClass().getClassLoader().getResource("..\\").getPath();


jdom:   
SAXBuilder builder = new SAXBuilder();
document = builder.build("student.xml");
Element root = document.getRootElement();
List<Element>  list= root.getChildren();
Element child = list.get(0);
child.getName()
child.getText());

Element root= new Element("Student");
root.setAttribute("gender", "female");
root.addContent(new Element("name").setText("Mary"))

XMLOutputter outputter = new XMLOutputter();
Format fmt = Format.getPrettyFormat();    //缩进的长度
outputter.output(root.getDocument(),new FileWriter("t.xml"));
  

dom4j

Document对象相关
SAXReader reader = new SAXReader();
Document document = reader.read(new File("t.xml"));
Document document = DocumentHelper.createDocument();
Element root = document.addElement("root"); // 创建根节点

节点相关
Element root = document.getRootElement();
Element e = root.element("son");
String text = e.getText();
String text=root.elementText("name"); 取得根节点下的name字节点的文字.
List<Element> elements = root.elements("son");
Element age = e.addElement("age");
age.setText("29");
pe.remove(ce);

属性相关
Element root=document.getRootElement();   
Attribute attribute=root.attribute("size");// 属性名name
String text=attribute.getText();
String text=root.element("name").attributeValue("firstname");
Iterator<Attribute> it=root.attributeIterator()
e.addAttribute("name", "sitinspring");
attr.setText("sitinspring");
root.remove(attr);


//文档中含有中文,设置编码格式写入的形式.
OutputFormat format = OutputFormat.createPrettyPrint();
format.setEncoding("GBK");    // 指定XML编码       
XMLWriter writer = new XMLWriter(new FileWriter("output.xml"),format);
writer.write(document);
writer.close();

String xml = doc.asXML();
String xml = root.asXML();
String xml = e.asXML();

XPath快速找到节点. // jaxen-1.1-beta-7.jar.
List<Element> list=doc.selectNodes("/root/child/t"); 

 

  
File   文件和目录抽象表示形式。 

getPath() / getAbsolutePath() / toURI()

isDirectory() / isFile()

long lastModified()  / long length()  //文件不存在返回0L, 目录返回值不确定

boolean delete()  目录必须为空才能删除
String[] list()  /  
String[] list(FileFilter filter)

mkdir() 创建目录。
exists() / createNewFile() 
 

Properties

getProperty( String key)

加载属性文件 load(InputStream in)

保存属性 store(OutputStream out ) 

 

System.getProperty(" ")    

java.class.path          Java 类路径            // -

java.library.path          加载库时搜索的路径列表  

java.ext.dirs           一个或多个扩展目录的路径   //

os.version            操作系统的版本

file.separator           文件分隔符

path.separator         路径分隔符

line.separator           行分隔符

user.home            用户的主目录                  

user.dir            用户的当前工作目录    

 

ResourceBundle和Properties 都是读取properties格式文件的

Properties同时还能用来写文件

ResourceBundle提供国际化功能。 

properties文件不能直接使用中文,通过native2ascii转换

 

节点流、处理流       字节流、字符流

 

节点流: FileXXX   CharArrayXXX   StringXXX    PipedXXX 

处理流: BufferedXXX    FilterXXX等

 

InputStreamReader、OutputStreamWriter  字节流字符流转换类

ObjectInputStream、ObjectOutputStream   

DataInputStream、DataOutputStream  

FileXXX   BufferedXXX   

PrintWriter、PrintStream 

系统输入流:Scanner scanner = new Scanner(System.in)

 

(whilebr.readLine()==null){} 

 

System.out.println("i am %s , value is %2.5f.","sky",15.0)

%d 十进制数    %x 十六进制数   %f 浮点数  %c 字符    %%输出"%"

%s 字符串      %b 布尔值    n$ 表示第n个args参数。1$ 表示第一个日期格式符: c  : 完整显示日期      

 

System.setIn(InputStream in)System.setOut(PrintStream out)

 

 

   [/color]

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics