commonproperty.java

来自「此文档包含有AOP」· Java 代码 · 共 45 行

JAVA
45
字号
package test.property;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Properties;

import test.consts.Messages;

public class CommonProperty {
	private static final String inFile =Messages.getString("propertyfile"); //$NON-NLS-1$
	private static final String inFile2 =Messages.getString("xmlfile"); //$NON-NLS-1$
	public static void main(String[] args) {
		boolean propertyToXml=true;
		Properties p = new Properties();
		File file = new File(inFile);
		File file2 = new File(inFile2);

		try {
			if(propertyToXml){
				System.out.println("Property file to Xml file!");
				FileInputStream in = new FileInputStream(file);
				FileOutputStream out = new FileOutputStream(file2);
				p.load(in);
				p.storeToXML(out, Messages.getString("ptoxComment")); //$NON-NLS-1$
				//PropertyResourceBundle bind = new PropertyResourceBundle(in);
			}else{
				System.out.println("Xml file to Property file!");
				FileInputStream in = new FileInputStream(file2);
				FileOutputStream out = new FileOutputStream(file);
				p.loadFromXML(in);
				p.store(out, Messages.getString("TestConst.xtopComment")); //$NON-NLS-1$
			}
			System.out.println(p.get("age")); //$NON-NLS-1$
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}//end catch
		
	}	// End Main
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?