首页 > 文档 > loadStrings()读取Strings数组
2017
07-14

loadStrings()读取Strings数组

3-8.loadStrings()

Name(名称):

Examples(例子):

String[] lines = loadStrings(“list.txt”);

println(“there are ” + lines.length + ” lines”);

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

println(lines[i]);

}

String[] lines = loadStrings(“http://processing.org/about/index.html”);

println(“there are ” + lines.length + ” lines”);

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

println(lines[i]);

}

Description(描述):Reads the contents of a file and creates a String array of its individual lines. 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.

读取文件的内容并创建其各行的String数组。如果使用文件的名称作为参数,如上例所示,文件必须加载到草图的”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。

Starting with Processing release 0134, all files loaded and saved by the Processing API use UTF-8 encoding. In previous releases, the default encoding for your platform was used, which causes problems when files are moved to other platforms.

从处理版本0134开始,Processing API加载和保存的所有文件都使用UTF-8编码。在以前的版本中,使用了您的平台的默认编码,当文件移动到其他平台时,会导致问题。

Syntax(语法):loadStrings(filename)

loadStrings(reader)

Parameters (参数):filename——name of the file or url to load要加载的文件或URL的名称

Returns(返回值):String[]

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



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

留下一个回复

你的email不会被公开。