日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 运维知识 > linux >内容正文

linux

Linux下生成指定大小文件(命令+Java程序)

發(fā)布時(shí)間:2024/7/19 linux 35 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Linux下生成指定大小文件(命令+Java程序) 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

1、dd命令

of:fileName為文件名稱,例如test.txt ;

bs:設(shè)置一次復(fù)制的大小,例如1M;

count:設(shè)置復(fù)制次數(shù),例如100;

dd if=/dev/zero of=<fileName> bs=<一次復(fù)制的大小> count=<復(fù)制的次數(shù)>

例如:

dd if=/dev/zero of=1.txt bs=1M count=100

2、Java快速生成

兩種方式都可以生成

package com.jxnu.test;import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.RandomAccessFile; import java.nio.ByteBuffer; import java.nio.channels.FileChannel;/*** @program: CreateFile* @author: xiaojing* @create: 2020-03-01-09-46*/ public class Test {public static void main(String[] args) throws IOException {File file = new File("test.txt");long length = 1024*1024*15;//createFixLengthFile(file, length);createFile(file, length);}/*** 第一種方法* @param file* @param length* @throws IOException*/public static void createFixLengthFile(File file, long length) throws IOException{FileOutputStream fos = null;FileChannel output = null;try {fos = new FileOutputStream(file);output = fos.getChannel();output.write(ByteBuffer.allocate(1), length - 1);} finally {try {if (output != null) {output.close();}if (fos != null) {fos.close();}} catch (IOException e) {e.printStackTrace();}}}/*** * 第二種方法* @param file* @param length* @throws IOException*/private static void createFile(File file, long length) throws IOException {RandomAccessFile r = null;try {r = new RandomAccessFile(file, "rw");r.setLength(length);} finally {if (r != null) {r.close();}}} }

總結(jié)

以上是生活随笔為你收集整理的Linux下生成指定大小文件(命令+Java程序)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。