//获取系统当前时间 public static String currentlyTime() { Date date = new Date(); DateFormat dateFormat = DateFormat.getDateInstance(DateFormat.FULL); return dateFormat.format(date); }
// 创建文件夹 public File createFile(String path) { File file = new File(path); if (!file.exists()) { file.mkdirs(); } return file; }
// 复制文件夹 public boolean copyFile(String source_path, String dest_path) { boolean flag = false; createFile(dest_path); File[] file_source = new File(source_path).listFiles(); for (int i = 0; i < file_source.length; i++) { if (file_source[i].isFile()) { try { FileInputStream input = new FileInputStream(file_source[i]); FileOutputStream output = new FileOutputStream(dest_path + "/" + file_source[i].getName()); byte[] b = new byte[1024 * 5]; int len; while ((len = input.read(b)) > 0) { output.write(b, 0, len); } output.flush(); output.close(); input.close(); } catch (Exception e) { e.printStackTrace(); } // 如果发现源目录下包含子目录的话,则递归调用copyFile()方法; if (file_source[i].isDirectory()) { copyFile(source_path + "/" + file_source[i].getName(), dest_path + "/" + file_source[i].getName()); } } flag = true; } return flag; }