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

📄 jdomparser.java

📁 这是一个实施监控程序, 这是一个实施监控程序,
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
				String s=java.io.File.separator;
				if(new File(url+s+file1[j]).isFile()){
				
			
				list.add(new String(url+s+file1[j]));
				
				
				}
			}
		}
		
			for(int i=0;i<list.size();i++){
				System.out.println("2222222         "+list.get(i));
			}
		return list;
	}
	/**
	 * 复制文件到指定目录。targetDir是目标目录,file是源文件名,newName是重命名的名字。
	 * 
	 * @param targetFile
	 * @param file
	 * @param newName
	 */
	public  void copyFileToDir(String targetDir, File srcfile) {
		//System.out.println("------------源文件是: "+srcfile.getPath());
		String srcPath=srcfile.getPath();
		String s=File.separator;
		String sub=srcPath.substring(0,srcPath.lastIndexOf(s));
		String typeP=sub.substring(sub.lastIndexOf(s)+1,sub.length());
		// java.util.Calendar c = java.util.Calendar.getInstance();
		
		//java.text.SimpleDateFormat fmt=new java.text.SimpleDateFormat("yyyyMMddHHmmss");
		//SimpleDateFormat fmt=new SimpleDateFormat("yyyyMMdd");
		//targetDir=targetDir.replace("/", s);
		
		File typeDir=new File(targetDir+s+typeP);
			if(!typeDir.exists()){
				typeDir.mkdir();
			}
		File subFolder=new File(targetDir+s+typeP+s+formatDate());
		
			if(!subFolder.exists()){
				subFolder.mkdir();
			}
		String newFile = "";
		String newName=srcPath.substring(srcPath.lastIndexOf(s)+1,srcPath.length());

		newFile=subFolder+s+newName;
		File tFile = new File(newFile);
		copyFile(tFile, srcfile);
	}

	
	/**
	 * 复制文件。targetFile为目标文件,file为源文件
	 * 
	 * @param toFile
	 * @param srcfile
	 */
	public  void copyFile(File toFile, File srcFile) {
		System.out.println("-----------src是----------"+srcFile);
		if (toFile.exists()) {
			
			System.out.println("文件" + toFile.getAbsolutePath()
					+ "已经存在,跳过该文件!");
			return;
			//如果解析 的文件是重复的,需要再重新命名一个文件.文件最后以四位不重复的
			//随机数字组成.xml
//			System.out.println("-----------src是----------"+srcFile);
//			String subStr=toFile.getPath().substring(0,toFile.getPath().indexOf("_")+1);
//			System.out.println("::::::::::::::::::     "+toFile.getPath()+"--------------subStr "+subStr);
//			String newName=null;
//			int hour=getHours();
//			int minute=getMinutes();
//			int second=getSeconds();
		} 
		System.out.println("复制文件---" + srcFile.getAbsolutePath() + "--到"
				+ toFile.getAbsolutePath());
		try {
			InputStream is = new FileInputStream(srcFile);
			FileOutputStream fos = new FileOutputStream(toFile);
			byte[] buffer = new byte[1536];
			while (is.read(buffer) != -1) {
				fos.write(buffer);
			}
			is.close();
			fos.close();
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	public void delThisFile(String path){
		File f=new File(path);
			if(f.exists()){
				try{
				f.delete();
				}catch(SecurityException ex){
					ex.printStackTrace();
				}
			}
	}
		/**
		 * 返回当前的时间,形如"20080122093528"的字符串
		 * @return
		 */
	public synchronized String formatDateTime(){
		
		java.text.SimpleDateFormat fmt=new java.text.SimpleDateFormat("yyyyMMddHHmmss");
		 return fmt.format(Calendar.getInstance().getTime());
	}
		/**
		 * 返回当前的日期形如“20080120”的字符串
		 * @return
		 */
	public synchronized String formatDate(){
		java.text.SimpleDateFormat sdf=new java.text.SimpleDateFormat("yyyyMMdd");
		return sdf.format(Calendar.getInstance().getTime());
	}

	
	//生成xml 文件
		public void buildXmlDoc(List recList,String bakDir){
			//System.out.println("----------------进来了---");
			Element root =new Element("Packet");//创建根节点
			Document doc=new Document(root);
			Element packethead=new Element("PacketHead");
			Element recNum=new Element("RecordNum");
			Element recType=new Element("Type");
			
			String recNo=this.getRecordNum().toString(); //包记录数
			String headtype=this.getType();				//包类型
//			文件名命名
			String fDir=bakDir+java.io.File.separator+headtype;
			packethead.addContent(recNum.setText(recNo));
			packethead.addContent(recType.setText(headtype));
			root.addContent(packethead);
			
			for(int i=0;i<recList.size();i++){
				Record rec=(Record)recList.get(i);
				Element recordRoot=new Element("Record");
				Element FDLX=new Element("FDLX");
				Element WZH=new Element("WZH");
				Element JZZL=new Element("JZZL");
				Element DABH=new Element("DABH");
				Element JSZH=new Element("JSZH");
				Element JYBH=new Element("JYBH");
				Element SF=new Element("SF");
				Element CPH=new Element("CPH");
				Element HPZL=new Element("HPZL");;
				Element CFSJ=new Element("CFSJ");
				Element WZDD=new Element("WZDD");
				Element FKJE=new Element("FKJE");
				Element WZJF=new Element("WZJF");
				Element WZDM1=new Element("WZDM1");
				Element WZDM2=new Element("WZDM2");
				Element XM=new Element("XM");
				Element XZQH=new Element("XZQH");
				Element FZJG=new Element("FZJG");
				Element JD=new Element("JD");
				Element WD=new Element("WD");
				recordRoot.addContent(FDLX.setText(rec.getFDLX().toString()));
				recordRoot.addContent(WZH.setText(rec.getWZH()));
				recordRoot.addContent(JZZL.setText(rec.getJZZL()));
				recordRoot.addContent(DABH.setText(rec.getDABH()));
				recordRoot.addContent(JSZH.setText(rec.getJSZH()));
				recordRoot.addContent(JYBH.setText(rec.getJYBH()));
				recordRoot.addContent(SF.setText(rec.getSF()));
				recordRoot.addContent(CPH.setText(rec.getCPH()));
				recordRoot.addContent(HPZL.setText(rec.getHPZL()));
				recordRoot.addContent(CFSJ.setText(rec.getCFSJ().toString()));
				recordRoot.addContent(WZDD.setText(rec.getWZDD()));
				recordRoot.addContent(FKJE.setText(rec.getFKJE().toString()));
				recordRoot.addContent(WZJF.setText(rec.getWZJF().toString()));
				recordRoot.addContent(WZDM1.setText(rec.getWZDM1()));
				recordRoot.addContent(WZDM2.setText(rec.getWZDM2()));
				recordRoot.addContent(XM.setText(rec.getXM()));
				recordRoot.addContent(XZQH.setText(rec.getXZQH()));
				recordRoot.addContent(FZJG.setText(rec.getFZJG()));
				recordRoot.addContent(JD.setText(rec.getJD()));
				recordRoot.addContent(WD.setText(rec.getWD()));
				root.addContent(recordRoot);
			}
			
			java.io.File folder=new java.io.File(fDir);
				if(!folder.exists()){
					folder.mkdir();
				}
			java.util.Date dt=new java.util.Date(System.currentTimeMillis());
			
			java.text.SimpleDateFormat sdf=new java.text.SimpleDateFormat("yyyyMMddHHmmss");
			
			String dateFolder=fDir+java.io.File.separator+sdf.format(dt).substring(0,8);
				java.io.File folder2=new java.io.File(dateFolder);
				if(!folder2.exists()){
					folder2.mkdir();
				}
				String bagType=this.getType();
			String fName="6000"+bagType+"_"+sdf.format(dt)+".xml";
			boolean newLine=true;
			
			
			 XMLOutputter XMLOut = new XMLOutputter();
			 Format format=Format.getPrettyFormat();
			 format.setEncoding("GB2312");
			 //输出XML文件
			 XMLOut.setFormat(format);
			OutputStream out = null;
			 try {
				// System.out.println("::::::::::::::::::::::");
				 out=new FileOutputStream(dateFolder+File.separator+fName);
				// System.out.println("----------------------已送入");
				XMLOut.output(doc, out);
				//System.out.println("------------ 操作的文件为: "+fName);
				out.close();
			} catch (FileNotFoundException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}finally{
				try {
					if(out!=null)	
						out.close();
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
		}
		
		

		
		
		
		
		
		public static void main(String args[]){

				java.util.Date dt=new java.util.Date(System.currentTimeMillis());
				java.text.SimpleDateFormat sdf=new java.text.SimpleDateFormat("yyyyMMdd");
				java.text.SimpleDateFormat fmt=new java.text.SimpleDateFormat("ss");
				
				java.util.Calendar c = java.util.Calendar.getInstance();
				 System.out.println(fmt.format(dt));
				 System.out.println(sdf.format(dt)+getHours()+getMinutes()+getSeconds());
				 System.out.println(c.get(Calendar.MINUTE));
				 System.out.println();
				 
						 
		}
		

}
	
	

⌨️ 快捷键说明

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