1. 在指定文件夹底下随机生成文件夹及文件
1.1 参数
参数名 |
含义 |
默认值 |
path |
生成文件夹路径 |
/home/cathay10/workSpace/log |
minSum |
随机数生成器 |
20 |
randomSum |
随机文件数量,最大为minSum+randomSum |
10 |
startDate |
指定开始日期,为空则默认1970-01-01开始 |
2021/01/01 |
numberOfDates |
生成的日期数量 |
9 |
plusDays |
日期偏移量,输入0为当前日期,正数为当前日期后n天,负数为当前日期前n天 |
0 |
prefix |
文件名前缀 |
log_ |
suffix |
文件名后缀 |
_log |
fileType |
文件类型 |
_log |
fileName |
文件名 |
file |
fileNameRandom |
文件名随机数长度(含数字、字母) |
6 |
charSize |
设置数组大小为1MB,可以根据需要调整 |
10 * 1024 * 1024 |
fileSize |
设置文件大小为1MB,可以根据需要调整 |
10 * 1024 * 1024 |
fillChar |
填充字符,用于填充文件大小 |
x |
生成的文件夹格式/ /home/cathay10/workSpace/log/yyyy/MM/dd/ |
|
|
1.2 代码
package com.api.apidemo.tool.file;
import org.apache.commons.lang3.StringUtils;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.*;
public class BatchCreateFile {
public static final String path = "/home/cathay10/workSpace/log";
static Random random = new Random();
static int minSum = 5;
static int randomSum =