createWriter()

本参考资料用于Processing 3.0+。 如果你使用的是前一版本,请在使用软件帮助菜单内的参考资料。. If you see any errors or have suggestions, please let us know. If you prefer a more technical reference, visit the Processing Core Javadoc and Libraries Javadoc.

名称

createWriter()

示例
 PrintWriter output;



void setup()
{  
// Create a new file in the sketch directory   output = createWriter("positions.txt");

  } 
void draw()
{  
point(mouseX, mouseY);


output.println(mouseX + "t" + mouseY);

// 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
  }  
描述 Creates a new file in the sketch folder, and a PrintWriter object to write to it. For the file to be made correctly, it should be flushed and must be closed with its flush() and close() methods (see above example).

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.

语法
createWriter(filename)
参数
filename String: name of the file to be created
返回值 PrintWriter
相关 createReader()

Updated on October 2, 2018 05:02:07pm EDT

createWriter()