# Generating txt.file in real time

**URL:** <https://discourse.processing.org/t/generating-txt-file-in-real-time/49116>\
**Category:** Coding Questions\
**Created:** [August 5, 2026, 9:23am UTC](https://discourse.processing.org/t/generating-txt-file-in-real-time/49116 "2026-08-05T09:23:56Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![stephan](https://avatars.discourse-cdn.com/v4/letter/s/8baadc/32.png) [@stephan](https://discourse.processing.org/u/stephan)\
**Post date:** [August 5, 2026, 9:23am UTC](https://discourse.processing.org/t/generating-txt-file-in-real-time/49116/1 "2026-08-05T09:23:56Z")

</div>

**Hi Forum, greetings from Holland.**

I want to check all random HSB-values the Mac Book is generating for me in Processing 3.5.4.  
So I inserted the next lines:

**// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - check  
println();  
println(“A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A”);  
println(rndSB);  
println(“H”, hA);  
println(“S”, sA);  
println(“B”, bA);**  
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

Note: not only for A, but also for B, C and D.  
Works pretty nice, but alas the number of lines the console is willing to present seems rather limited.

Therefore the next QUESTION: **is there a way to collect all text in real time (as “output”) and produce/export one (larger) txt.file?**  
If yes, how? Thank you in advance.

---

<div class="post-metadata">

**Author:** ![quark](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/quark/32/26_2.png) [@quark](https://discourse.processing.org/u/quark)\
**Post date:** [August 5, 2026, 11:18am UTC](https://discourse.processing.org/t/generating-txt-file-in-real-time/49116/2 "2026-08-05T11:18:40Z")

</div>

Welcome to the forum 😄

The console output window is restricted to how much it can display, removing old output and appending new output. The solution is to store your output in an arraylist and then save it in a simple ASCII text file.

It is unlikely that you can see the whole text file in the console window but will be viewable in its entirety using a text editor e.g. TextEdit.

This sketch demonstrates how to do this and should be easy to adapt to your own sketch.

```processing
ArrayList<String> output = new ArrayList<String>();
boolean recording = false;
String filename = "";

void setup() {
  size(640, 480);
  fill(0);
  textSize(20);
  textAlign(LEFT, TOP);
}

void draw() {
  background(200, 200, 255);
  text("Mouse position and click recorder", 10, 20);
  text("Key 1 : start / resume recording", 30, 50);
  text("Key 2 : pause recording", 30, 80);
  text("Key C : clear current log", 30, 110);
  text("Key S : save current log to file", 30, 140);

  text("STATUS : "+ (recording ? "RECORDING" : "PAUSED"), 30, 200);
  text("LAST FILE LOG : " + filename, 30, 240);
}

void mouseMoved() {
  if (recording ) {
    output.add("Mouse moved to " + mouseX + "' " + mouseY);
  }
}

void mouseClicked() {
  if (recording ) {
    output.add("Mouse clicked at " + mouseX + "' " + mouseY);
  }
}

void mouseDragged(){
  if (recording ) {
    output.add("Mouse dragged to " + mouseX + "' " + mouseY);
  }
}

void keyTyped() {
  switch(key) {
  case '1':
    recording = true;
    break;
  case '2':
    recording = false;
    break;
  case 'c':
    output.clear();
    break;
  case 's':
    filename = "output-" + millis() + ".txt";
    String[] strings = (String[])output.toArray(new String[output.size()]);
    saveStrings(filename, strings);
  }
}

```

---

<div class="post-metadata">

**Author:** ![svan](https://avatars.discourse-cdn.com/v4/letter/s/82dd89/32.png) [@svan](https://discourse.processing.org/u/svan)\
**Post date:** [August 5, 2026, 6:44pm UTC](https://discourse.processing.org/t/generating-txt-file-in-real-time/49116/3 "2026-08-05T18:44:02Z")

</div>

Alternate technique using PrintStream: toggle output from console to file with keys ‘c’ and ‘f’.

```processing
import java.io.*;

PrintStream f, console;

void setup() {
  size(400, 400);
  console = System.out;
  try {
    f = new PrintStream(sketchPath("") + new File("hsb.txt"));
  }
  catch(Exception e) {
    println("Unable to create file output stream: ", e);
  }
  System.setOut(console);
}

void draw() {
  color c = color(random(255), random(255), random(255));
  float value = hue(c);
  println("hue =", value);
  float value2 = saturation(c);
  println("saturation =", value2);
  float value3 = brightness(c);
  println("brightness =", value3);
  println("=======================");
  background(c);
}

void keyTyped() {
  if (key == 'c')
    System.setOut(console);
  else if (key == 'f')
    System.setOut(f);
}

```

---

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [August 6, 2026, 12:48am UTC](https://discourse.processing.org/t/generating-txt-file-in-real-time/49116/4 "2026-08-06T00:48:20Z")

</div>

Hello @stephan,

There are some options here:

> **[Reference](https://processing.org/reference/)**
>
> Find further documentation of the Processing language

See:

> **[saveStrings() / Reference](https://processing.org/reference/saveStrings_)**
>
> Writes an array of Strings to a file, one line per String. By default, this file is saved to the sketch's folder. This folder is opened by selecting "Show Sketch Folder" from the "Sketch" menu. \<…

> **[PrintWriter / Reference](https://processing.org/reference/PrintWriter)**
>
> Allows characters to print to a text-output stream. A new PrintWriter object is created with the createWriter() function. For the file to be made correctly, it should be flushed and must be clo…

If you want to see what is happening under the hood search for the methods above here:

> <https://github.com/processing/processing4/blob/main/core/src/processing/core/PApplet.java>

`:)`
