<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
    主站蜘蛛池模板: 亚洲经典在线观看| 亚洲伦理一区二区| 亚洲国产精品ⅴa在线观看| 日韩不卡免费视频| 中文在线免费看视频| 国产国产成年年人免费看片| 亚洲精品亚洲人成在线播放| 久久久久国产精品免费免费搜索 | 中国人xxxxx69免费视频| 免费国产成人高清在线观看麻豆 | 国产精品xxxx国产喷水亚洲国产精品无码久久一区 | 成人无码a级毛片免费| 亚洲不卡av不卡一区二区| 亚洲精品无码中文久久字幕| 无码人妻精品一二三区免费| 亚洲AV日韩AV一区二区三曲| 免费va人成视频网站全| 亚洲一区二区三区免费| 亚洲AV成人一区二区三区AV| 在线观看免费中文视频| 亚洲AV日韩AV永久无码绿巨人| 日韩人妻一区二区三区免费| 国产精品亚洲片在线va| 国产精品黄页在线播放免费| 色爽黄1000部免费软件下载| 亚洲国产精品VA在线观看麻豆| 84pao强力永久免费高清| 亚洲一级特黄特黄的大片 | 成在人线av无码免费高潮水| 亚洲av无码专区国产乱码在线观看| 91精品导航在线网址免费| 亚洲深深色噜噜狠狠网站| 亚洲国产一区二区三区| 一级毛片在线免费看| 亚洲中文字幕久久久一区| 亚洲国产成人久久一区WWW| 无码AV片在线观看免费| 亚洲AV无码专区亚洲AV桃| 亚洲精品一品区二品区三品区| 免费99精品国产自在现线| sss日本免费完整版在线观看|