将文件的字节获取到数组

问题描述 投票:0回答:1

我使用以下 7 行将文件

NameF
的字节放入 FreeBasic 0.4.6 FBide 中的向量
T()

有更好或更短的方法吗?

DIM L as ulong, NameF as string
Input "Enter Name of the File", NameF
Open NameF For Binary As #1
L= LOF(1)
Close #1
DIM T(1 to L) As Ubyte
Open NameF For Binary Access Read As #1
Get #1, , T()
Close #1

7条线工作正常。如果可行的话,我正在寻求改进。

basic freebasic
1个回答
0
投票

减少2行是一个进步,谢谢大家

那么 3 行就更好了(不需要单独的 L 变量,以及冗余的

Close
Open
命令):

DIM NameF as string
Input "Enter Name of the File", NameF
Open NameF For Binary Access Read As #1
DIM T(1 to LOF(1)) As Ubyte
Get #1, , T()
Close #1
© www.soinside.com 2019 - 2024. All rights reserved.