0
点赞
收藏
分享

微信扫一扫

JAVA 创建任意大小的文件

西红柿上校 2022-08-08 阅读 113


public void CreateBigFile() {



byte[] memFile = new byte[FILE_SIZE];

for (int i = 0; i < FILE_SIZE; i++) {

memFile[i] = (byte) (i % 20);

}



RandomAccessFile randomFile = null;

try {

randomFile = new RandomAccessFile(PATH+FILENAME, "rw");



for (int i = 0; i < BEI_SHU; i++) {

long fileLength = randomFile.length();

randomFile.seek(fileLength);

randomFile.write(memFile);

}



} catch (FileNotFoundException e) {

e.printStackTrace();

} catch (IOException e) {

e.printStackTrace();

}

}

举报

相关推荐

0 条评论