gpt4 book ai didi

processing - 我怎么能选择一个特定的文件来加载 loadStrings

转载 作者:行者123 更新时间:2023-12-04 04:59:36 25 4
gpt4 key购买 nike

标题够明确,我想让用户选择他想要打开的文本文件。
我不知道是否已经在处理中实现了资源管理器或输入字段。

任何帮助都会很棒。

最佳答案

使用 selectInput .从处理引用:

Opens a platform-specific file chooser dialog to select a file for input. After the selection is made, the selected File will be passed to the 'callback' function. If the dialog is closed or canceled, null will be sent to the function, so that the program is not waiting for additional input. The callback is necessary because of how threading works.



我修改了他们在引用中提供的示例草图,以包括使用 loadStrings 加载文件方法。
String[] txtFile;

void setup() {
selectInput("Select a file to process:", "fileSelected");
}

void fileSelected(File selection) {
if (selection == null) {
println("Window was closed or the user hit cancel.");
} else {
String filepath = selection.getAbsolutePath();
println("User selected " + filepath);
// load file here
txtFile = loadStrings(filepath);
}
}

关于processing - 我怎么能选择一个特定的文件来加载 loadStrings,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16302332/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com