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?
我有一个字节数组,我想计算如果我把这些字节写入文件,文件的大小是多少。是否可以不将文件写入磁盘?
3 个解决方案
#1
62
What about array.Length
? Looks like a size in bytes.
array.Length呢?看起来是字节大小。
#2
37
Um, yes:
嗯,是的,
int length = byteArray.Length;
A byte in memory would be a byte on disk... at least in higher level file system terms. You also need to potentially consider how many individual blocks/clusters would be used (and overhead for a directory entry), and any compression that the operating system may supply, but it's not clear from the question whether that's what you're after.
内存中的字节就是磁盘上的字节……至少在高级文件系统术语中是这样。您还需要考虑使用多少个单独的块/集群(以及一个目录条目的开销),以及操作系统可能提供的任何压缩,但是从这个问题上看不清楚这是否是您想要的。
If you really do want to know the "size on disk" as opposed to the file size (in the same way that Windows can show the two numbers) I suspect you'd genuinely have to write it to disk - and then use a Win32 API to find out the actual size on disk.
如果你真的想知道“磁盘大小”而不是文件的大小(以同样的方式,窗口可以显示两个数字)我怀疑你真的不得不写磁盘,然后使用Win32 API来找到磁盘上的实际大小。
#3
4
Array.Length
would give your total size expressed in byte.
Physical dimension on disk may be a little bit more considering cluster size.
数组中。长度将给出以字节表示的总大小。考虑到集群大小,磁盘上的物理维度可能稍微多一些。
#1
62
What about array.Length
? Looks like a size in bytes.
array.Length呢?看起来是字节大小。
#2
37
Um, yes:
嗯,是的,
int length = byteArray.Length;
A byte in memory would be a byte on disk... at least in higher level file system terms. You also need to potentially consider how many individual blocks/clusters would be used (and overhead for a directory entry), and any compression that the operating system may supply, but it's not clear from the question whether that's what you're after.
内存中的字节就是磁盘上的字节……至少在高级文件系统术语中是这样。您还需要考虑使用多少个单独的块/集群(以及一个目录条目的开销),以及操作系统可能提供的任何压缩,但是从这个问题上看不清楚这是否是您想要的。
If you really do want to know the "size on disk" as opposed to the file size (in the same way that Windows can show the two numbers) I suspect you'd genuinely have to write it to disk - and then use a Win32 API to find out the actual size on disk.
如果你真的想知道“磁盘大小”而不是文件的大小(以同样的方式,窗口可以显示两个数字)我怀疑你真的不得不写磁盘,然后使用Win32 API来找到磁盘上的实际大小。
#3
4
Array.Length
would give your total size expressed in byte.
Physical dimension on disk may be a little bit more considering cluster size.
数组中。长度将给出以字节表示的总大小。考虑到集群大小,磁盘上的物理维度可能稍微多一些。