| Author |
Make a file of desired size using java ?
|
Rahul Sudip Bose
Ranch Hand
Joined: Jan 21, 2011
Posts: 637
|
|
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.
|
SCJP 6. Learning more now.
|
 |
Jesper de Jong
Java Cowboy
Bartender
Joined: Aug 16, 2005
Posts: 12953
|
|
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).
|
Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
|
 |
Rahul Sudip Bose
Ranch Hand
Joined: Jan 21, 2011
Posts: 637
|
|
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.
|
 |
Wouter Oet
Saloon Keeper
Joined: Oct 25, 2008
Posts: 2700
|
|
|
It might depending on what you want to do. Just open one of many tutorials about I/O and see for yourself.
|
"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." --- Martin Fowler
Please correct my English.
|
 |
Rob Spoor
Sheriff
Joined: Oct 27, 2005
Posts: 19232
|
|
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.
|
SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
|
 |
Rahul Sudip Bose
Ranch Hand
Joined: Jan 21, 2011
Posts: 637
|
|
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
Joined: Jan 21, 2011
Posts: 637
|
|
|
Thanks ! I needed it for my app here
|
 |
 |
|
|
subject: Make a file of desired size using java ?
|
|
|