0
我不知道如何保存在处理一个txt文件,我已经尝试了一些不同的东西,但每次好像该文件的时间是因为重载:处理保存到.txt文件?
output = createWriter("positions.txt");
,如果我尝试删除此行,或尝试其他的东西来检查文件是否坚持,然后不运行该行,ia NullPointerException。
有什么办法可以保存文件而不会覆盖文件?
PrintWriter output;
void setup() {
// Create a new file in the sketch directory
output = createWriter("positions.txt");
}
void draw() {
point(mouseX, mouseY);
output.println(mouseX); // Write the coordinate to the file
}
void keyPressed() {
output.flush(); // Writes the remaining data to the file
output.close(); // Finishes the file
exit(); // Stops the program
}
该文件被覆盖,因为您使用相同的路径'“positions.txt”'。如果您想每次创建一个新文件,请使用'while'或'for'循环遍历数字,以检查是否存在“+”位置“+ number +”.txt“。继续下去,直到文件不存在并将其用作路径。 – Nathangrad
@khelwood这不是Java处理 - createWriter是Processing的本地函数。考虑到这一点,运算处理!= Java,所以值得移除Java标记。 –