Processing, createWriter()
用法介紹。
用法
createWriter(filename)
參數
filename
(String)
要創建的文件的名稱
返回
PrintWriter
說明
在草圖文件夾中創建一個新文件,以及一個要寫入該文件的 PrintWriter
對象。為了正確製作文件,它應該被刷新並且必須用它的flush()
和close()
方法關閉(見上麵的例子)。
從處理版本 0134 開始,處理 API 加載和保存的所有文件都使用 UTF-8 編碼。在以前的版本中,使用了您平台的默認編碼,這在將文件移動到其他平台時會導致問題。
例子
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
}
有關的
相關用法
- Processing createFont()用法及代碼示例
- Processing createImage()用法及代碼示例
- Processing createShape()用法及代碼示例
- Processing createInput()用法及代碼示例
- Processing createReader()用法及代碼示例
- Processing createGraphics()用法及代碼示例
- Processing case用法及代碼示例
- Processing clip()用法及代碼示例
- Processing camera()用法及代碼示例
- Processing curveDetail()用法及代碼示例
- Processing catch用法及代碼示例
- Processing char()用法及代碼示例
- Processing ceil()用法及代碼示例
- Processing curveVertex()用法及代碼示例
- Processing concat()用法及代碼示例
- Processing continue用法及代碼示例
- Processing color()用法及代碼示例
- Processing copy()用法及代碼示例
- Processing cos()用法及代碼示例
- Processing circle()用法及代碼示例
- Processing char用法及代碼示例
- Processing color用法及代碼示例
- Processing class用法及代碼示例
- Processing curve()用法及代碼示例
- Processing curveTightness()用法及代碼示例
注:本文由純淨天空篩選整理自processing.org大神的英文原創作品 createWriter()。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。