findfile.java
来源:互联网 发布:2016年网络星期一 编辑:程序博客网 时间:2024/05/16 08:37
- /**************************************
- * Title: 查找指定目录文件
- * Description: FileFilter类
- * date : 2006-3-25
- * author : zhanglei
- ***************************************/
- package server;
- import java.io.*;
- public class findfile {
- private String pathname;
- private DomXML DomXML = MainServer.DomXML;
- public findfile(String pathname) {
- this.pathname = pathname;
- }
- private static FileFilter fileFilter = new FileFilter() {
- public boolean accept(File pathname) {
- String tmp = pathname.getName().toLowerCase();
- //if(tmp.endsWith(".xml")){
- if (tmp.indexOf(".") != -1) {
- //System.out.println(tmp);
- return true;
- }
- //}
- return false;
- }
- };
- //获得文件列表
- public File[] GetFile() {
- try {
- File root = new File(pathname);
- File[] files = root.listFiles(fileFilter);
- return files;
- }
- catch (Exception e) {
- System.out.println("GetFile" + pathname + "文件夹不存在!" + e);
- return null;
- }
- /* for(int i=0; i<files.length; i++)
- {
- System.out.println(i + "name " + files[i]);
- }*/
- }
- /**
- *BackFile 备份XML文件
- *@param1 doFile 被移动文件
- *@param2 return 备份后文件
- */
- public File BackFile(File yFile) {
- File bakFile = null; //备份文件
- File bakDir = null; //备份文件路径
- File doDir = null; //备份文件路径
- File doFile = null; //移动后的处理文件
- String bakPath = "";
- String recvPath = "";
- try {
- //创建备份路径
- DomXML.GetBeginItem("PathConfig");
- if (DomXML.GetItemAttribute("bak_dir", "run").toLowerCase().trim().equals("y")) {
- bakPath = DomXML.GetItemAttribute("bak_dir", "path");
- bakDir = new File(bakPath + "/" + MyFunction.DataTimeStr("yyyyMMdd"));
- if (!bakDir.exists()) {
- bakDir.mkdirs();
- }
- //备份XML文件
- bakFile = new File(bakDir.getPath() + "/" + yFile.getName());
- if (bakFile.exists()) {
- bakFile.delete();
- }
- MyFunction.CopyFile(yFile.toString(), bakFile.toString());
- }
- //移动目标文件
- recvPath = DomXML.GetItemAttribute("recv_up", "path").trim();
- doDir = new File(recvPath);
- if (!doDir.exists()) {
- doDir.mkdirs();
- }
- doFile = new File(recvPath + "/" + yFile.getName());
- if (doFile.exists()) {
- doFile.delete();
- }
- yFile.renameTo(doFile);
- return doFile;
- }
- catch (Exception e) {
- System.out.println(e + "文件备份失败!");
- return null;
- }
- }
- /**
- *MoveErrorFile 移动异常XML文件
- *@param1 doFile 被移动文件
- *@param2 return 0正确,-1错误
- */
- public int MoveErrorFile(File doFile) {
- File errorFile = null;
- File errorDir = null; //异常文件路径
- try {
- DomXML.GetBeginItem("PathConfig");
- if (DomXML.GetItemAttribute("error_dir", "run").trim().toUpperCase().equals("Y")) {
- errorDir = new File(DomXML.GetItemAttribute("error_dir", "path").trim() + "/" + MyFunction.DataTimeStr("yyyyMMdd"));
- if (!errorDir.exists()) {
- errorDir.mkdirs();
- }
- errorFile = new File(errorDir.getPath() + "/" + doFile.getName());
- if (errorFile.exists()) {
- errorFile.delete();
- }
- doFile.renameTo(errorFile);
- }
- else {
- doFile.delete();
- }
- return 0;
- }
- catch (Exception e) {
- System.out.println(e + "移动异常文件失败!");
- return -1;
- }
- }
- public static void main(String[] args) {
- File bakFile = new File("D:/JB_Work/XmlServer/ErrorXmlFile/test36.xml");
- findfile FindFile = new findfile("D:/JB_Work/XmlServer/recv_dir");
- FindFile.MoveErrorFile(bakFile);
- }
- }
- findfile.java
- FindFile
- findfile
- findfile
- findFile
- FindFile
- findfile
- findfile用法
- CFileFind::FindFile
- CFtpFileFind FindFile卡住的问题
- CFtpFileFind FindFile卡住的问题
- GetFileAttributes失败时可以尝试用FindFile代替
- CFileFind中FindFile与API中FindFirstFile的区别
- CFileFind中FindFile与API的FindFirstFile区别(CSDN问题)
- FindFile FindNextFile 如何遍历一个文件夹并获取里面文件的信息
- MFC中利用FindFile函数在文件夹路径下连续读取多个文件
- java
- JAVA
- 定义一个计算操作时间的宏
- pedump.c
- 启动进程——使用CreateProcess需注意的地方
- 直接运行内存中的程序
- 仿真WINDOWS PE加载器的程序
- findfile.java
- 用自删除dll实现应用程序的安装/卸载代码
- Apache ServiceMix 3.x User's Guide
- getxml.java
- 常用中断
- listxml.java
- DOS批处理中%~dp0表示什么意思
- 为什么使用Serializable(序列化)
- jdbcwork.java