xml压缩代码java xml压缩率( 三 )


private static final String FILE_SPE = "/";
private static final String CHANGE_LINES = "\n";
private static final String FILE_NAME = "text.xml";
public static void main(String[] args) {
String xml = appendStr();
try {
File file = createXmlFile(FILE_PATH + FILE_SPE + FILE_NAME);
writeDoc(file, xml);
System.out.println("文件已经创建:");
System.out.println("目录:" + FILE_PATH + FILE_SPE + FILE_NAME);
System.out.println("文件内容为:");
System.out.println(xml);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
/**
* 组装XML内容
* @return
*/
private static String appendStr(){
StringBuffer sb = new StringBuffer();
sb.append(XML_TITLE).append(CHANGE_LINES);
sb.append("book").append(CHANGE_LINES);
sb.append("name").append(CHANGE_LINES);
sb.append("《好玩》").append(CHANGE_LINES);
sb.append("/name").append(CHANGE_LINES);
sb.append("/book").append(CHANGE_LINES);
return sb.toString();
}
/**
* 将内容写入文件
* @param file
* @param str
*/
private static void writeDoc(File file,String str){
OutputStream out = null;
try {
out = new FileOutputStream(file);
out.write(str.getBytes());
}catch(Exception ex){
//
ex.printStackTrace();
}finally{
if(out != null){
try {
out.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
/**
*创建文件
* @param path
* @return
* @throws IOException
*/
private static File createXmlFile(String path) throws IOException{
File file = new File(path);
if(!file.exists()){
file.createNewFile();
}
return file;
}
}
【xml压缩代码java xml压缩率】xml压缩代码java的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于xml压缩率、xml压缩代码java的信息别忘了在本站进行查找喔 。

推荐阅读