Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Fixed size file

 
Angela D'souza
Ranch Hand
Posts: 469
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to create file which will contains some record details. Each record must be 16 byte fixed size. How can I create 16 byte fixed size file for each record?
Thanks,
Angela
 
Maulin Vasavada
Ranch Hand
Posts: 1873
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Angela
i am not clear about your question. initially u say that u wanted a file where there are multiple records and each record is of 16 byte size....but in the end sentence you say that you want "16 byte fixed size file for each record"...
so i assume that you want a file,
1. where there are number of records
2. you don't know the number of records
3. each record is 16 bytes
4. you want to create a file that can constraint the record size to be 16 bytes
well, this is not possible it seems. if u were able to know the number of records say N then you can do math 16*N bytes file size. but still you can't create a file that puts restriction of 16*N bytes capacity.
what you can do is,
you can create byte[] of 16 bytes for each record and then create array (Object array) of thoes records and then dump each of them in the file.
i don't think that Java can control file size factor as its OS dependent.
regards
maulin.
 
Angela D'souza
Ranch Hand
Posts: 469
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Maulin Vasavada:
hi Angela
so i assume that you want a file,
1. where there are number of records
2. you don't know the number of records
3. each record is 16 bytes
4. you want to create a file that can constraint the record size to be 16 bytes
regards
maulin.

Sorry for not clear. Yes ur right.
I want a file:
(1) Where I want to add multiple records(I don't the total number of records).
(2) Each record (i add to file) has to be fixed size-16 bytes
Thanks
Angela
 
Angela D'souza
Ranch Hand
Posts: 469
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you have any other good suggestions???
Thanks,
Angela
 
Maulin Vasavada
Ranch Hand
Posts: 1873
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Angela
i don't think we have a way to do this. we have to put wrapper like i suggested that will restrict input in the way you want so you don't run into file size violation ever.
thanks
maulin.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic