现在的位置: 首页 > 综合 > 正文

JAVA 创建任意大小的文件

2013年12月05日 ⁄ 综合 ⁄ 共 409字 ⁄ 字号 评论关闭

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();
}
}

抱歉!评论已关闭.