Unable to write data in a text file

File getting created successfully but data is not getting written in file.

code:-

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
}

code looks ok, did you try to use size() and save the sketch prior to using

works for me


PrintWriter output;

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

void draw() {
  point(mouseX, mouseY);
  if (mouseX!=0)
    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
}
5t164
7t161
8t159
10t154
14t143
14t143
22t128
27t119
29t115
29t115
29t115
29t115
29t115
30t113
32t107
33t104
33t104
33t104
33t104
33t104
33t104
33t104
33t104
33t104
33t104
33t104
33t104
33t104
33t104
33t104
33t104
33t104
35t109
35t109
35t109
49t135
49t135
53t145
53t145
56t148
62t151
69t155
74t159
79t160
79t160
85t161
92t161
92t161
92t161
92t161
109t158
111t157
113t156
117t154
120t152
125t147
125t147
127t144
128t140
129t136
132t131
132t131
133t126
133t121
133t120
131t119
128t118
122t115
122t115
116t115
114t115
112t115
109t117
105t121
101t125
97t131
97t131
94t139
90t146
88t152
86t157
86t157
86t163
86t169
86t175
86t179
86t179
89t187
89t187
90t188
94t190
97t191
102t191
102t191
109t191
117t191
124t191
131t190
131t190
135t188
135t188
135t188
135t188
135t188
135t188
136t187
137t187
137t187
137t187
137t187
139t184
139t184
142t178
148t171
153t164
158t158
158t158
163t154
167t151
170t149
175t147
180t145
180t145
193t141
193t141
198t140
199t138
199t138
200t138
200t137
200t136
201t129
201t129
202t109
202t109
202t103
200t94
197t90
197t88
197t88
196t87
196t87
196t87
196t87
196t86
196t86
196t84
196t84
196t84
196t84
196t83
196t83
197t82
200t81
209t81
218t81
218t81
233t77
233t77
235t75
238t74
238t74
239t74
240t73
240t73
240t73
240t73
241t73
241t73
241t73
241t73
241t73
241t73
241t73
241t73
241t73
241t73
241t73
241t73
241t74
241t78
241t87
241t98
240t107
240t107
240t115
240t123
240t133
240t143
240t143
240t153
240t162
240t170
240t174
240t176
240t176
240t176
240t176
240t176
240t176
240t176
240t176
240t176
240t176
240t176
240t176
239t176
231t176
217t176
217t176
199t176
186t177
182t177
182t177
182t177
182t177
181t177
181t177
180t178
178t178
176t179
176t179
176t179
176t179
176t179
176t179
176t179
176t179
176t179
176t179
176t174
176t169
176t161
176t153
177t140
177t140
177t123
177t109
179t98
179t93
179t93
179t89
179t89
179t89
179t89
179t89
179t89
179t87
179t87
179t86
179t86
179t85
179t85
179t85
179t85
179t85
179t85
179t85
179t85
179t85
179t85
179t85
179t85
179t85
179t85
179t85
179t85
179t85
179t85
179t85
179t85
179t85
179t85
179t85
179t85
179t85
179t85
179t85
179t85
179t85
179t85
179t85
179t85
179t85
179t85
179t85
179t85
179t85
179t85
179t85
179t85
179t85
179t85
179t85
179t85
179t85
179t85
179t86
180t93
180t93
180t103
178t107
178t110
177t114
177t114
177t114
177t114
177t114
177t114
177t114
175t116
175t116
175t116
175t116
175t116
175t116
173t117
167t119
165t119
165t119
165t119
165t119
165t119
165t119
165t119
165t119
165t119
165t119
162t121
156t122
149t123
136t126
136t126
119t128
109t132
109t132
109t132
109t132
109t132
109t132
109t132
109t132
109t132
109t132
109t132
109t132
109t132
109t132
109t132
109t132
109t132
109t132
109t132
109t132
109t132
109t132
109t132
109t132
109t132
109t132
109t132
109t132
109t132
109t132
109t132
109t132
109t132
109t132
109t132
109t132
109t132