• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Paul Clapham
  • Bear Bibeault
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Jj Roberts
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • salvin francis
  • Scott Selikoff
  • fred rosenberger

Make a file of desired size using java ?

 
Ranch Hand
Posts: 637
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please suggest some ways to make java code which generates a file of size entered by the user. The range can be from a few bytes (bits also possible ???) to many megabytes.
Thanks.
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What data should the file contain, or does it not matter?

You can just open a FileOutputStream and write as many bytes to it as is necessary. You cannot create a file with a fractional number of bytes (for example, a file with 4 bits).
 
Rahul Sudip Bose
Ranch Hand
Posts: 637
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Jesper de Jong wrote:What data should the file contain, or does it not matter?



Random characters. Does the code change according to the data that this file may contain ? Please give examples.
 
Bartender
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It might depending on what you want to do. Just open one of many tutorials about I/O and see for yourself.
 
Sheriff
Posts: 22018
108
Eclipse IDE Spring VI Editor Chrome Java Ubuntu Windows
  • Likes 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You don't need to actually write anything, using RandomAccessFile:
I can use this to create an 8GB file within a second. The file will use 0 to fill the file.
 
Rahul Sudip Bose
Ranch Hand
Posts: 637
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Rob Spoor wrote:You don't need to actually write anything, using RandomAccessFile:
I can use this to create an 8GB file within a second. The file will use 0 to fill the file.



Thanks ! I tried that and it works well.
 
Rahul Sudip Bose
Ranch Hand
Posts: 637
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks ! I needed it for my app here
 
Ever since I found this suit I've felt strange new needs. And a tiny ad:
the value of filler advertising in 2020
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic