create JPEG/txt any type file which requires to be

2019-06-07 07:56发布

问题:

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??

回答1:

Yes It is possible.

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