我设计使用本Java中的归档格式(只是为了好玩)模板 -如何截断java整数以适合/ exand到给定数量的字节?
First 4 bytes: Number of files in the archive
Next 4 bytes: Number of bytes in the filename
Next N bytes: Filename
Next 10 bytes: Number of bytes in the file
Next N bytes: File contents
从PHP Safe way to download mutliple files and save them。
我有问题找到文件数量的值等,但我不知道如何将一个整数扩展为4个字节。
它是类似于这 - How do I truncate a java string to fit in a given number of bytes, once UTF-8 encoded?
在你的代码中,我认为第2行有错误。意外的int关键字? – liamzebedee 2011-05-04 09:36:46
糟糕,错误,修复。 – WhiteFang34 2011-05-04 09:37:43
我知道一个字节是8位,而java中的整数是32位。那么这意味着我甚至不需要经历所有这些,只需要写整数,因为整数是4个字节(32位) – liamzebedee 2011-05-04 09:40:50