Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get file's size from bytes array (without saving to disc)

Tags:

arrays

c#

.net

I have a byte's array and I want to calculate what would be the file size if I'll write these bytes to file. Is it possible without writing the file to disc?

like image 676
nKognito Avatar asked Dec 02 '12 12:12

nKognito


People also ask

How do you determine the size of a byte array?

Find length of one array element in bytes and total bytes consumed by the elements in Numpy. In NumPy we can find the length of one array element in a byte with the help of itemsize . It will return the length of the array in integer.

How do I get bytes from MemoryStream?

To get the entire buffer, use the GetBuffer method. This method returns a copy of the contents of the MemoryStream as a byte array. If the current instance was constructed on a provided byte array, a copy of the section of the array to which this instance has access is returned.

Can we print byte array?

You can simply iterate the byte array and print the byte using System. out. println() method.

Can we convert byte array to file in Java?

Convert byte[] array to File using Java In order to convert a byte array to a file, we will be using a method named the getBytes() method of String class. Implementation: Convert a String into a byte array and write it in a file.


1 Answers

What about array.Length? Looks like a size in bytes.

like image 172
Sergey Berezovskiy Avatar answered Sep 29 '22 20:09

Sergey Berezovskiy