backup.java

来自「cwbbs 云网论坛源码」· Java 代码 · 共 65 行

JAVA
65
字号
package cn.js.fan.util;import java.io.*;import cn.js.fan.util.file.*;import cn.js.fan.db.*;public class Backup {  public Backup() {  }  public static void copyDirectory(String filedes, String filesrc) throws      IOException {    (new File(filedes)).mkdirs();    File[] file = (new File(filesrc)).listFiles();    if (file==null)         return;    for (int i = 0; i < file.length; i++) {      if (file[i].isFile()) {        FileInputStream input = new FileInputStream(file[i]);        FileOutputStream output = new FileOutputStream(filedes + "/" +            file[i].getName());        byte[] b = new byte[1024 * 5];        int len;        while ( (len = input.read(b)) != -1) {          output.write(b, 0, len);        }        output.flush();        output.close();        input.close();      }      if (file[i].isDirectory()) {        copyDirectory(filedes + "/" + file[i].getName(),                       filesrc+ "/" + file[i].getName());      }    }  }  public void generateZipFile(String srcpath, String zipfilepath) throws IOException  {      Compress cps = new Compress();      cps.zipDirectory(srcpath, zipfilepath);  }  public boolean BackupDB(String dbName, String poolName, String dbfile) {            String sql = "BACKUP DATABASE " + dbName + " TO DISK = '" +                   dbfile + "' with init";       Conn conn = new Conn(poolName);      try {          conn.executeUpdate(sql);      }      catch (Exception e) {          System.out.print("BackupDB:" + e.getMessage());          return false;      }      finally {          if (conn!=null) {              conn.close(); conn = null;          }      }      return true;  }}

⌨️ 快捷键说明

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