<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    隨筆-314  評論-209  文章-0  trackbacks-0

    業務常用,供大家學習:

    引用地址:http://www.easydone.cn/014/200604022353065155.htm

    package org.easydone.file;



    import java.io.File;
    import java.io.FileWriter;
    import java.io.IOException;
    import java.io.PrintWriter;
    import java.text.SimpleDateFormat;
    import java.util.Date;

    /**
     * <p>Title: File 常用操作(部分)</p>
     * <p>Description: 業務用</p>
     * <p>Copyright: Copyright (c) 2006 www.easydone.cn</p>
     * <p>Company: 北京聚能易成科技有限公司</p>
     * @authory dirboy
     * @version 1.0
     */

    public class FileOperate {

        /**
        * 創建目錄
        * @param folderPath:目錄路徑
        * @return
        * @throws IOException
        */
        public static boolean createFolder(String folderPath) throws IOException {
            boolean result = false;
            File f = new File(folderPath);
            result = f.mkdirs();
            return result;
        }
        /**
        * 刪除目錄下所有文件
        * @param directory (File 對象)
        */
        public void emptyDirectory(File directory) {
            File[] entries = directory.listFiles();
            for (int i = 0; i < entries.length; i++) {
                entries[i].delete();
            }
        }


        /**
        * 創建文件
        * @param filepath:文件所在目錄路徑,比如:c:/test/test.txt
        * @return
        */
        public static boolean makeFile(String filepath) throws IOException {
            boolean result = false;
            File file = new File(filepath);
            result = file.createNewFile();
            file = null;
            return result;
        }
        /**
        * 刪除文件
        * @param filepath:文件所在物理路徑
        * @return
        */
        public static boolean isDel(String filepath) {
            boolean result = false;
            File file = new File(filepath);
            result = file.delete();
            file = null;
            return result;
        }
        /**
        * 文件重命名
        * @param filepath:文件所在物理路徑
        * @param destname:新文件名
        * @return
        */
        public static boolean renamefile(String filepath,String destname) {
            boolean result = false;
            File f = new File(filepath);
            String fileParent = f.getParent();
            String filename = f.getName();
            File rf = new File(fileParent+"http://"+destname);
            if(f.renameTo(rf)) {
                result = true;
            }
            f = null;
            rf = null;
            return result;
        }
        /**
        * 將文件內容寫入數據庫中
        * @param filepath:文件所在物理路徑
        * @param content:寫入內容
        * @throws Exception
        */
        public static void WriteFile(String filepath,String content) throws Exception {
            FileWriter filewriter = new FileWriter(filepath,true);//寫入多行
            PrintWriter printwriter = new PrintWriter(filewriter);
            printwriter.println(content);
            printwriter.flush();
            printwriter.close();
            filewriter.close();
        }
        /**
        * 日志備份
        * @param filePath:日志備份路徑
        * @param baksize:日志備份大小參考值(字節大小)
        * @throws IOException
        */
        public static void logBak(String filePath,long baksize) throws IOException {
            File f = new File(filePath);
            long len = f.length();
            SimpleDateFormat simpledateformat = new SimpleDateFormat("yyyyMMddHHmmss");
            String s = simpledateformat.format(new Date());
            String fileName = f.getName();
            int dot = fileName.indexOf(".");
            String bakName = s+fileName.substring(dot);
            System.out.println(bakName);
            if(len>=baksize) {
                renamefile(filePath,bakName);
                makeFile(filePath);
            }
            f = null;
        }

    }

    posted on 2007-06-14 16:52 xzc 閱讀(2058) 評論(0)  編輯  收藏 所屬分類: Java
    主站蜘蛛池模板: 国产成人免费高清在线观看| 欧美大尺寸SUV免费| 日韩亚洲国产二区| 亚洲av无码专区首页| 日韩a在线观看免费观看| 亚洲另类自拍丝袜第五页| 高清国语自产拍免费视频国产| 亚洲一区二区三区乱码在线欧洲| 毛片免费vip会员在线看| 亚洲欧洲专线一区| 国产免费av片在线无码免费看| 精品女同一区二区三区免费播放| 免费国产在线观看| 久久久久国色AV免费观看| 日本亚洲成高清一区二区三区 | 在线永久看片免费的视频| 亚洲一区二区三区免费在线观看| 91视频国产免费| 成人婷婷网色偷偷亚洲男人的天堂 | 在线观看午夜亚洲一区| 毛片免费在线观看| 亚洲人成影院在线高清| 免费看国产精品麻豆| 久久精品成人免费网站| 精品亚洲AV无码一区二区三区| 日韩高清免费在线观看| 亚欧国产一级在线免费| 亚洲精品视频专区| 日产乱码一卡二卡三免费| 中出五十路免费视频| 亚洲日本在线观看网址| 亚洲国产人成精品| 精品熟女少妇av免费久久| 亚洲精品色在线网站| 久久久久亚洲AV成人无码| 免费人成在线视频| 国产精品免费视频观看拍拍 | 亚洲成AV人片在线播放无码| 免费无码黄十八禁网站在线观看| www.xxxx.com日本免费| 国产精品亚洲精品|