java创建指定大小文件@TOC
软件功能测试中经常遇到上传文件大小校验功能,我们需要构造多种情况用于边界测试,因此需要创建不同大小的文件。
java中使用RandomAccessFile类可快速创建,代码如下:
package com
.study
.demo
;
import java
.io
.*
;
public class CreaterFile {
public static void main(String
[] args
) throws FileNotFoundException
, IOException
{
int cap
= 5*1024*1024;
RandomAccessFile r
= new RandomAccessFile("E:\\test\\test1.xlsx", "rw");
r
.setLength(cap
);
r
.close();
}
}