Skip to content

Commit 0ace61f

Browse files
committed
PrintWriter and BufferedReader files added to includes in reference
1 parent ae08475 commit 0ace61f

14 files changed

+846
-0
lines changed
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
2+
<root>
3+
<name>BufferedReader</name>
4+
5+
<category>Input</category>
6+
7+
<subcategory>Files</subcategory>
8+
9+
<usage>Web &amp; Application</usage>
10+
11+
<example>
12+
<image></image>
13+
<code><![CDATA[
14+
BufferedReader reader;
15+
String line;
16+
17+
void setup() {
18+
// Open the file from the createWriter() example
19+
reader = createReader("positions.txt");
20+
}
21+
22+
void draw() {
23+
try {
24+
line = reader.readLine();
25+
} catch (IOException e) {
26+
e.printStackTrace();
27+
line = null;
28+
}
29+
if (line == null) {
30+
// Stop reading because of an error or file is empty
31+
noLoop();
32+
} else {
33+
String[] pieces = split(line, TAB);
34+
int x = int(pieces[0]);
35+
int y = int(pieces[1]);
36+
point(x, y);
37+
}
38+
}
39+
]]></code>
40+
</example>
41+
42+
<description><![CDATA[
43+
A <b>BufferedReader</b> object is used to read files line-by-line as individual <b>String</b> objects.
44+
<br/><br/>
45+
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.
46+
]]></description>
47+
48+
<method>
49+
<mname>readLine()</mname>
50+
<mdescription>returns a String that is the current line in the text file</mdescription>
51+
</method>
52+
53+
<syntax></syntax>
54+
55+
<parameter>
56+
<label></label>
57+
<description></description>
58+
</parameter>
59+
60+
<returns></returns>
61+
62+
<related>
63+
createReader()
64+
try
65+
catch
66+
</related>
67+
68+
<availability>1.0</availability>
69+
70+
<type>Function</type>
71+
72+
<partof>Core</partof>
73+
74+
</root>
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
2+
<root>
3+
4+
<name>readLine()</name>
5+
6+
<category>BufferedReader</category>
7+
8+
<subcategory>Method</subcategory>
9+
10+
<usage>Web &amp; Application</usage>
11+
12+
<example>
13+
<image></image>
14+
<code><![CDATA[
15+
BufferedReader reader;
16+
String line;
17+
18+
void setup() {
19+
// Open the file from the createWriter() example
20+
reader = createReader("positions.txt");
21+
}
22+
23+
void draw() {
24+
try {
25+
line = reader.readLine();
26+
} catch (IOException e) {
27+
e.printStackTrace();
28+
line = null;
29+
}
30+
if (line == null) {
31+
// Stop reading because of an error or file is empty
32+
noLoop();
33+
} else {
34+
String[] pieces = split(line, TAB);
35+
int x = int(pieces[0]);
36+
int y = int(pieces[1]);
37+
point(x, y);
38+
}
39+
}
40+
]]></code>
41+
</example>
42+
43+
<description><![CDATA[
44+
Returns a String that is the current line in the BufferedReader.
45+
]]></description>
46+
47+
<syntax>
48+
<c>br</c>.readLine()
49+
</syntax>
50+
51+
<parameter>
52+
<label>br</label>
53+
<description><![CDATA[any object of the type BufferedReader]]></description>
54+
</parameter>
55+
56+
57+
<returns>String</returns>
58+
59+
<related></related>
60+
61+
<availability>1.0</availability>
62+
63+
<type>Method</type>
64+
65+
<partof>Core</partof>
66+
67+
68+
</root>
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
2+
<root>
3+
<name>PrintWriter</name>
4+
5+
<category>Output</category>
6+
7+
<subcategory>Files</subcategory>
8+
9+
<usage>Web &amp; Application</usage>
10+
11+
<example>
12+
<image></image>
13+
<code><![CDATA[
14+
PrintWriter output;
15+
16+
void setup() {
17+
// Create a new file in the sketch directory
18+
output = createWriter("positions.txt");
19+
}
20+
21+
void draw() {
22+
point(mouseX, mouseY);
23+
output.println(mouseX); // Write the coordinate to the file
24+
}
25+
26+
void keyPressed() {
27+
output.flush(); // Writes the remaining data to the file
28+
output.close(); // Finishes the file
29+
exit(); // Stops the program
30+
}
31+
32+
]]></code>
33+
</example>
34+
35+
<description><![CDATA[
36+
Allows characters to print to a text-output stream. A new PrintWriter object is created with the <b>createWriter()</b> function. For the file to be made correctly, it should be flushed and must be closed with its <b>flush()</b> and <b>close()</b> methods (see above example).
37+
]]></description>
38+
39+
<method>
40+
<mname>print()</mname>
41+
<mdescription>Adds data to the stream</mdescription>
42+
</method>
43+
44+
<method>
45+
<mname>println()</mname>
46+
<mdescription>Adds data to the stream and starts a new line</mdescription>
47+
</method>
48+
49+
<method>
50+
<mname>flush()</mname>
51+
<mdescription>Flushes the stream</mdescription>
52+
</method>
53+
54+
<method>
55+
<mname>close()</mname>
56+
<mdescription>Closes the stream</mdescription>
57+
</method>
58+
59+
<returns></returns>
60+
61+
<related>
62+
createWriter()
63+
</related>
64+
65+
<availability>1.0</availability>
66+
67+
<type>Object</type>
68+
69+
<partof>Core</partof>
70+
71+
72+
</root>
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
2+
<root>
3+
4+
<name>close()</name>
5+
6+
<category>PrintWriter</category>
7+
8+
<subcategory>Method</subcategory>
9+
10+
<usage>Web &amp; Application</usage>
11+
12+
<example>
13+
<image></image>
14+
<code><![CDATA[
15+
PrintWriter output;
16+
17+
void setup() {
18+
output = createWriter("positions.txt"); // Create a new file in the sketch directory
19+
}
20+
21+
void draw() {
22+
point(mouseX, mouseY);
23+
output.println(mouseX); // Write the coordinate to the file
24+
}
25+
26+
void keyPressed() {
27+
output.flush(); // Writes the remaining data to the file
28+
output.close(); // Finishes the file
29+
exit(); // Stops the program
30+
}
31+
32+
]]></code>
33+
</example>
34+
35+
<description><![CDATA[
36+
Closes the <b>PrintWriter</b> object.
37+
]]></description>
38+
39+
<syntax>
40+
<c>pw</c>.close()
41+
</syntax>
42+
43+
<parameter>
44+
<label>pw</label>
45+
<description><![CDATA[any object of the type PrintWriter]]></description>
46+
</parameter>
47+
48+
49+
<returns></returns>
50+
51+
<related></related>
52+
53+
<availability>1.0</availability>
54+
55+
<type>Method</type>
56+
57+
<partof>Core</partof>
58+
59+
60+
</root>
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
2+
<root>
3+
4+
<name>flush()</name>
5+
6+
<category>PrintWriter</category>
7+
8+
<subcategory>Method</subcategory>
9+
10+
<usage>Web &amp; Application</usage>
11+
12+
<example>
13+
<image></image>
14+
<code><![CDATA[
15+
PrintWriter output;
16+
17+
void setup() {
18+
output = createWriter("positions.txt"); // Create a new file in the sketch directory
19+
}
20+
21+
void draw() {
22+
point(mouseX, mouseY);
23+
output.println(mouseX); // Write the coordinate to the file
24+
}
25+
26+
void keyPressed() {
27+
output.flush(); // Writes the remaining data to the file
28+
output.close(); // Finishes the file
29+
exit(); // Stops the program
30+
}
31+
32+
]]></code>
33+
</example>
34+
35+
<description><![CDATA[
36+
Flushes the <b>PrintWriter</b> object. This is necessary to ensure all remaining data is written to the file before it is closed.
37+
]]></description>
38+
39+
<syntax>
40+
<c>pw</c>.flush()
41+
</syntax>
42+
43+
<parameter>
44+
<label>pw</label>
45+
<description><![CDATA[any object of the type PrintWriter]]></description>
46+
</parameter>
47+
48+
49+
<returns></returns>
50+
51+
<related></related>
52+
53+
<availability>1.0</availability>
54+
55+
<type>Method</type>
56+
57+
<partof>Core</partof>
58+
59+
60+
</root>

0 commit comments

Comments
 (0)