首页 > 常用方法

Java写xml文件方法

发表于2014-09-03 15:18:37| --次阅读| 来源webkfa| 作者小周

摘要:Java写xml文件方法
java代码
/**
	 * 把xml字符串保存成xml文件
	 * @param path
	 * @param context
	 * @param charsetname
	 */
	public static void savexmlfile(String path,String context,String charsetname){
		if(path==null)return;
		if("".equals(path))return;
		if(charsetname==null || "".equals(charsetname))charsetname="UTF-8";
		FileOutputStream fos = null;
		try {
			fos = new FileOutputStream(path);
			
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} 
		OutputStreamWriter osw=null;
		try {
			osw = new OutputStreamWriter(fos,charsetname);
		} catch (UnsupportedEncodingException e2) {
			// TODO Auto-generated catch block
			e2.printStackTrace();
		} 
		BufferedWriter bw=new BufferedWriter(osw); 
		try {
			bw.append(context);
		} catch (IOException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		} 
		
		try {
			bw.close();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

相关文章

相关文章

友情链接: hao123 360导航 搜狗网址导航 114啦网址导航 博客大全
Copyright © 1999-2014, WEBKFA.COM, All Rights Reserved  京 ICP 证 14034497 号