首页 > 文档 > loadBytes()打开文件并读取其二进制数据
2017
07-14

loadBytes()打开文件并读取其二进制数据

3-5.loadBytes()

Name(名称):loadBytes()//

Examples(例子):

// Open a file and read its binary data打开文件并读取其二进制数据

byte b[] = loadBytes(“something.dat”);

 

// Print each value, from 0 to 255打印每个值,从0到255

for (int i = 0; i < b.length; i++) {

// Every tenth number, start a new line每十分之一,开始一条新线

if ((i % 10) == 0) {

println();

}

// bytes are from -128 to 127, this converts to 0 to 255字节从-128到127,这将转换为0到255

int a = b[i] & 0xff;

print(a + ” “);

}

// Print a blank line at the end最后打印一个空白行

println();

Description(描述):Reads the contents of a file and places it in a byte array. If the name of the file is used as the parameter, as in the above example, the file must be loaded in the sketch’s “data” directory/folder.

读取文件的内容并将其放置在字节数组中。 如果使用文件的名称作为参数,如上例所示,文件必须加载到草图的”data”目录/文件夹中。

Alternatively, the file maybe be loaded from anywhere on the local computer using an absolute path (something that starts with / on Unix and Linux, or a drive letter on Windows), or the filename parameter can be a URL for a file found on a network.

或者,该文件可以从本地计算机上的任何地方使用绝对路径(以/ Unix和Linux开头的东西或Windows上的驱动器盘符)加载,或者filename参数可以是在 网络。

If the file is not available or an error occurs, null will be returned and an error message will be printed to the console. The error message does not halt the program, however the null value may cause a NullPointerException if your code does not check whether the value returned is null.

如果文件不可用或出现错误,将返回null,并将错误消息打印到控制台。 错误消息不会停止程序,但是如果您的代码不检查返回的值是否为空,则空值可能会导致NullPointerException。

Syntax(语法):loadBytes(filename)

Parameters (参数):filename——name of a file in the data folder or a URL.数据文件夹中的文件名或URL。

Returns(返回值):byte[]

Related(相关函数):loadStrings()
saveStrings()
saveBytes()



最后编辑:
作者:卡萨布兰卡
这个作者貌似有点懒,什么都没有留下。

留下一个回复

你的email不会被公开。