首页 > 文档 > createInput()创建输入
2017
07-14

createInput()创建输入

3-2.createInput()

Name(名称):createInput()//读取文件

Examples(例子):

// Load the local file ‘data.txt’ and initialize a new InputStream加载本地文件”data.txt”并初始化一个新的InputStream

InputStream input = createInput(“data.txt”);

String content = “”;

try {

int data = input.read();

while (data != -1) {

content += data;

data = input.read();

}

}

catch (IOException e) {

e.printStackTrace();

}

finally {

try {

input.close();

}

catch (IOException e) {

e.printStackTrace();

}

}

println(content);

Description(描述):This is a shorthand function for advanced programmers to initialize and open a Java InputStream. It’s useful if you want to use the facilities provided by PApplet to easily open files from the data folder or from a URL, but you need an InputStream object so that you can use other parts of Java to take more control of how the stream is read.

这是高级程序员初始化和打开Java InputStream的简写功能。如果要使用PApplet提供的工具轻松地从数据文件夹或URL打开文件,但是您需要一个InputStream对象,以便您可以使用Java的其他部分来更好地控制流如何读取,这很有用。

The filename passed in can be:

– A URL, as in: createInput(“http://processing.org/”)

– The name of a file in the sketch’s data folder

– The full path to a file to be opened locally (when running as an application)

传入的文件名可以是:

– 一个URL,如:createInput(”http://processing.org/”)

– 草图数据文件夹中文件的名称

– 要在本地打开的文件的完整路径(作为应用程序运行时)

If the requested item doesn’t exist, null is returned. If not online, this will also check to see if the user is asking for a file whose name isn’t properly capitalized. If capitalization is different, an error will be printed to the console. This helps prevent issues that appear when a sketch is exported to the web, where case sensitivity matters, as opposed to running from inside the Processing Development Environment on Windows or Mac OS, where case sensitivity is preserved but ignored.

如果请求的项目不存在,则返回null。如果不在线,这也将检查用户是否要求一个名称不正确大写的文件。如果大小写不同,则会将错误打印到控制台。这有助于防止在将草图导出到Web时出现的问题,其中区分大小写重要,而不是在Windows或Mac OS上的处理开发环境内运行,其中区分大小写被保留但被忽略。

If the file ends with .gz, the stream will automatically be gzip decompressed. If you don’t want the automatic decompression, use the related function createInputRaw().

如果文件以.gz结尾,流将自动gzip解压缩。如果不想自动解压缩,请使用相关函数createInputRaw()。

In earlier releases, this function was called openStream().

在早期的版本中,这个函数叫做openStream()。

Syntax(语法):createInput(filename)

Parameters (参数):filename——要用作输入的文件的名称

Returns(返回值):InputStream

Related(相关函数):createOutput()
selectOutput()
selectInput()



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

留下一个回复

你的email不会被公开。