Writes data to the print stream with new lines added.
The parameter, data
, is the data to write. data
can be a number or string, as in myWriter.print('hi')
, or an array of numbers and strings, as in myWriter.print([1, 2, 3])
. A comma will be inserted between array array elements when they're added to the print stream.
示例
function setup() {
createCanvas(100, 100);
background(200);
// Style the text.
textAlign(LEFT, CENTER);
textFont('Courier New');
textSize(12);
// Display instructions.
text('Double-click to save', 5, 50, 90);
describe('The text "Double-click to save" written in black on a gray background.');
}
// Save the file when the user double-clicks.
function doubleClicked() {
// Create a p5.PrintWriter object.
let myWriter = createWriter('numbers.txt');
// Add some data to the print stream.
myWriter.print('1,2,3,');
myWriter.print(['4', '5', '6']);
// Save the file and close the print stream.
myWriter.close();
语法
print(data)
参数
data
String|Number|Array:
data to be written as a string, number, or array of strings and numbers.
Notice any errors or typos? Please let us know. Please feel free to edit src/io/files.js and open a pull request!