创建JPEG / TXT要求任何类型的文件加以固定尺寸,其用户将给予尺寸、类型、文件、用户

2023-09-06 09:00:46 作者:时光深存少年梦i

我要创建JPEG / TEXT / MP3任意类型根据用户要求文件要求加以固定的大小也将被用户放弃,如500 KB,1兆不论大小,也对路径的SD卡也将提供按用户。但我不知道如何来实现这一目标。谁可以教我如何制作/创建它?

I want to create JPEG/TEXT/MP3 any type as per user requirement files which requires to be fixed size which will also give by user, e.g 500 KB,1 Mb whatever size and also on path in sdcard which will also provide by user. But I have no idea how to achieve that. Who can teach me how to make/create it??

推荐答案

是的,它是可能的。

我使用低于code实现,这样的事情。

I am using below code to achieve such things.

class Test {
     public static void main(String args[]) {
          try {
               RandomAccessFile f = new RandomAccessFile("t.txt", "rw");
               f.setLength(1073741824);// 1073741824 bytes = 1 GB
               f.write("Hello I am writing this file".getBytes());
               f.close();
          } catch (Exception e) {
               e.printStackTrace();
          }
     }
}