1. 生成大小相同,内容不同
int differentSize = 128 * 1024 + 1; //128 * 1024 + 1 代表是128k+1 byte[] content = RandomString.make(differentSize).getBytes();
2. 生成大小随机, 内容不同
int differentSize = new Random().nextInt(200 * 1024 * 1024) + 1; //单位:M byte[] content = RandomString.make(differentSize).getBytes();
3. 读指定路径下的文件 大小相同,内容相同
public static String readFilePath = "testdata/readfile/" public static String randonFileName(String filePath) { File file = new File(filePath); String[] filelist = file.list(); // for (int i = 0; i < filelist.length; i++) { // System.out.println(filelist[i]); // } int index = (int) (Math.random() * filelist.length); String random = filelist[index]; return random; }
//大小不同,内容相同. 读指定路径下的文件随机 //String readfile = readFilePath + randonFileName(DataUtil.readFilePath); //相同大小,内容相同. 读指定路径下的单个文件 String readfile = readFilePath + "20m"; System.out.println("文件路径: " + readfile); bytes = byteMap.computeIfAbsent(readfile, f -> { try { return Files.asByteSource(new File(f)).read(); } catch (Exception e) { throw new RuntimeException(e); } }); System.out.println("文件内容: " + new String(bytes));