<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 閱讀(2062) 評論(0)  編輯  收藏 所屬分類: Java
    主站蜘蛛池模板: 亚洲色偷偷偷综合网| 成人无码区免费视频观看| 高清国语自产拍免费视频国产 | 成全视频在线观看免费高清动漫视频下载 | 5555在线播放免费播放| 在线观看免费黄网站| 美女黄频a美女大全免费皮| 搡女人真爽免费视频大全| 亚洲国产精品无码一线岛国| 91免费国产视频| a级毛片在线免费观看| 曰批全过程免费视频免费看| 亚洲精品国产高清在线观看| 亚洲精品国产精品乱码不99| 在线a免费观看最新网站| 一级成人a毛片免费播放| 免费人成在线观看网站| 无码日韩精品一区二区免费暖暖| 久久香蕉国产线看免费| 日韩精品久久久久久免费 | 亚洲一区二区三区久久| 亚洲最大成人网色香蕉| 亚洲色偷偷狠狠综合网| 精品国产香蕉伊思人在线在线亚洲一区二区 | 久久久亚洲精品蜜桃臀| 亚洲va无码va在线va天堂| 亚洲国产精品不卡在线电影| 小小影视日本动漫观看免费| 亚洲XX00视频| 91免费资源网站入口| 国产乱子伦精品免费无码专区 | 国产精品亚洲精品观看不卡| 久久久久亚洲精品无码网址色欲| 黄色网页免费观看| 日本免费久久久久久久网站| 精品久久久久成人码免费动漫 | 免费毛片a线观看| 日本免费人成黄页网观看视频| 亚洲中文字幕久久精品无码喷水 | 无码国模国产在线观看免费| 国产中文在线亚洲精品官网|