⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 videoinfoxml.java

📁 模拟的土豆网视频网站
💻 JAVA
字号:
package cn.myvideosite.xml;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;

import org.jdom.Document;
import org.jdom.Element;
import org.jdom.output.Format;
import org.jdom.output.XMLOutputter;

import cn.myvideosite.data.model.bean.VideoInformation;
import cn.myvideosite.data.model.services.VideoInfoService;
import cn.myvideosite.util.MySuperDate;

public class VideoInfoXML {

	/**
	 * @param args使用xml保存视频
	 */
	public static void main(String[] args) {
	      
		 VideoInformation video = VideoInfoService.findByFlashAddr("http://www.56.com/u30/v_MzgwODg3MDc.html");
		
		 Element rootElement = new Element("videoinformation");
		 Document myDocument = new Document(rootElement);
		 
		 rootElement.addContent(new Element("videoId").setText(Integer.toString(video.getVideoId())));
		 rootElement.addContent(new Element("userId").setText(Integer.toString(video.getUserId())));
		 rootElement.addContent(new Element("uploadTime").setText(new MySuperDate(video.getUploadTime()).getDateString()));
		 rootElement.addContent(new Element("videoTitle").setText(video.getVideoTitle()));
		 rootElement.addContent(new Element("flowerNub").setText(Integer.toString(video.getFlowerNub())));
		 rootElement.addContent(new Element("channelId").setText(Integer.toString(video.getChannelId())));
		 rootElement.addContent(new Element("introduction").setText(video.getIntroduction()));
		 rootElement.addContent(new Element("flashAddress").setText(video.getFlashAddress()));
		 rootElement.addContent(new Element("score").setText(Integer.toString(video.getScore())));
		 rootElement.addContent(new Element("soureUrl").setText(video.getSoureUrl()));
		 rootElement.addContent(new Element("newUrl").setText(video.getNewUrl()));
		 rootElement.addContent(new Element("headTitle").setText(video.getHeadTitle()));
		 
		 XMLOutputter xmlOut = new XMLOutputter(Format.getPrettyFormat().setEncoding("utf-8"));
		 OutputStream os = null;
		       try {
				os = new FileOutputStream("D:\\javawork\\video\\videoinformation.xml");
				xmlOut.output(myDocument, os);
				
			} catch (FileNotFoundException e) {				
				e.printStackTrace();
			} catch (IOException e) {				
				e.printStackTrace();
			}finally{
				
				try {
					if(os != null){
						os.close();
						os = null;
					}					
				} catch (IOException e) {					
					e.printStackTrace();
				}
			}		       
	}

}

⌨️ 快捷键说明

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