# How to save console output as a .txt file

**URL:** <https://discourse.processing.org/t/how-to-save-console-output-as-a-txt-file/12353>\
**Category:** Electronics (Arduino, etc.)\
**Created:** [June 28, 2019, 6:27am UTC](https://discourse.processing.org/t/how-to-save-console-output-as-a-txt-file/12353 "2019-06-28T06:27:37Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![The\_nish](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/the_nish/32/5634_2.png) [@The\_nish](https://discourse.processing.org/u/The_nish)\
**Post date:** [June 28, 2019, 6:27am UTC](https://discourse.processing.org/t/how-to-save-console-output-as-a-txt-file/12353/1 "2019-06-28T06:27:37Z")

</div>

i am printing an image of binary and i want to print exactly this Image of String in .txt file.  
is this possible to take ouput of console print data to save as .txt file

 ![apple](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/3/3b90653908ff59ae01faf2c69f22cb88cffa2046.png)

---

<div class="post-metadata">

**Author:** ![jb4x](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jb4x/32/789_2.png) [@jb4x](https://discourse.processing.org/u/jb4x)\
**Post date:** [June 28, 2019, 8:05am UTC](https://discourse.processing.org/t/how-to-save-console-output-as-a-txt-file/12353/2 "2019-06-28T08:05:58Z")

</div>

Hi,  
I can see that you already have created a writer that you called output.

So now, you just need to replace your print and println statements by output.print and output.println

---

<div class="post-metadata">

**Author:** ![The\_nish](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/the_nish/32/5634_2.png) [@The\_nish](https://discourse.processing.org/u/The_nish)\
**Post date:** [June 28, 2019, 8:23am UTC](https://discourse.processing.org/t/how-to-save-console-output-as-a-txt-file/12353/3 "2019-06-28T08:23:37Z")

</div>

yes i did that .  
but i get this type of output

 ![upload](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/f/f859ae85eeec3f55b8f304c72abbe79e64a92947.png)

can u solved it .

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [June 28, 2019, 8:27am UTC](https://discourse.processing.org/t/how-to-save-console-output-as-a-txt-file/12353/4 "2019-06-28T08:27:53Z")

</div>

Missing line break at the end of each line

Try to print ”\n“ at the end of each line

---

<div class="post-metadata">

**Author:** ![The\_nish](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/the_nish/32/5634_2.png) [@The\_nish](https://discourse.processing.org/u/The_nish)\
**Post date:** [June 28, 2019, 8:38am UTC](https://discourse.processing.org/t/how-to-save-console-output-as-a-txt-file/12353/5 "2019-06-28T08:38:07Z")

</div>

yes i did that . but i get same value and characters are changed .

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [June 28, 2019, 9:01am UTC](https://discourse.processing.org/t/how-to-save-console-output-as-a-txt-file/12353/6 "2019-06-28T09:01:35Z")

</div>

Or use println instead of print

Please show your code

---

<div class="post-metadata">

**Author:** ![The\_nish](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/the_nish/32/5634_2.png) [@The\_nish](https://discourse.processing.org/u/The_nish)\
**Post date:** [June 28, 2019, 9:02am UTC](https://discourse.processing.org/t/how-to-save-console-output-as-a-txt-file/12353/7 "2019-06-28T09:02:46Z")

</div>

```auto
import processing.serial.*;
Serial myPort; 
PImage img;
PrintWriter output;
 String s;
 int i,j;

void setup()
{
  
  
  img = loadImage("vl.png");
  size(100,100);
  //loadPixels();
  img.loadPixels();
  output = createWriter("danish.txt");
    myPort = new Serial(this, "COM6",115200);
    noLoop();
}

void draw()
{

  function();   
  
}

void function()
{
    for (int y=0; y<img.height; y++)
  {
    for (int x=0; x<img.width; x++)

    {
      int i= x+y*width;
      
      //String s = str(i);
      
           if ((i+1)%100 == 1) {
        
        print("\n");
      }
  
    
     
        //int c = s.charAt(0);
        //print(c);
        
        
      if (img.pixels[i] == color(0,0,0))
      {
        
       i=1;
         
      } else 
      { 
    
       i=0;
      }
           
           
      
      String s = str(i);
      
       String[] q = splitTokens(s,"");
      String[] d = sort(q,q.length);
      
      for(j=0;j<q.length;j++)
      {
        print(q[j]);
       output.print(q[j]);
       myPort.write(q[j]);
       delay(2);
      }
      
    
    
      
   
  }
}

}

 

```

---

<div class="post-metadata">

**Author:** ![jb4x](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jb4x/32/789_2.png) [@jb4x](https://discourse.processing.org/u/jb4x)\
**Post date:** [June 28, 2019, 9:07am UTC](https://discourse.processing.org/t/how-to-save-console-output-as-a-txt-file/12353/8 "2019-06-28T09:07:26Z")

</div>

You missed an output.print("/n") line13 of your function called function.

Also please correctly format you code using ctrl+t on processing before posting it here.

---

<div class="post-metadata">

**Author:** ![The\_nish](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/the_nish/32/5634_2.png) [@The\_nish](https://discourse.processing.org/u/The_nish)\
**Post date:** [June 28, 2019, 9:14am UTC](https://discourse.processing.org/t/how-to-save-console-output-as-a-txt-file/12353/9 "2019-06-28T09:14:06Z")

</div>

if i am doing that i get this kind of output

 ![k](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/7/7ef69b67281e041c8265c3f3e24bbd50bd4d82f1.png)

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [June 28, 2019, 9:22am UTC](https://discourse.processing.org/t/how-to-save-console-output-as-a-txt-file/12353/10 "2019-06-28T09:22:42Z")

</div>

In notepad:

Is the display of line breaks activated?

See menu View

Or try to look at your file with another program like WordPad or MS Word

---

<div class="post-metadata">

**Author:** ![The\_nish](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/the_nish/32/5634_2.png) [@The\_nish](https://discourse.processing.org/u/The_nish)\
**Post date:** [June 28, 2019, 10:57am UTC](https://discourse.processing.org/t/how-to-save-console-output-as-a-txt-file/12353/11 "2019-06-28T10:57:50Z")

</div>

till not working.  
ok leave it and help me in another way  
i want to create image like in my above code console window. example(apple image in binary)  
this image is printing in console and when i want each row of this image sending to arduino but my string array is printing just like another example . tell me what is mistake in my code

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [June 28, 2019, 12:44pm UTC](https://discourse.processing.org/t/how-to-save-console-output-as-a-txt-file/12353/12 "2019-06-28T12:44:30Z")

</div>

Show your code please

Are you using some kind of LED grid? Which form?

---

<div class="post-metadata">

**Author:** ![The\_nish](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/the_nish/32/5634_2.png) [@The\_nish](https://discourse.processing.org/u/The_nish)\
**Post date:** [June 28, 2019, 1:01pm UTC](https://discourse.processing.org/t/how-to-save-console-output-as-a-txt-file/12353/13 "2019-06-28T13:01:12Z")

</div>

![21%20PM](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/5/5946f82c83ad0ffaf972e7a22468ddb8e65eb739.jpeg)

i am not using led grid . it just 100 led’s which are connected in serial through arduino.

---

<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:** [June 28, 2019, 2:44pm UTC](https://discourse.processing.org/t/how-to-save-console-output-as-a-txt-file/12353/14 "2019-06-28T14:44:46Z")

</div>

Are you using appropriate current limiting resistors?  
An LED exploded in one of our labs at work with low voltages (5V); it can happen.  
Always wear safety glasses when working on projects like this.

🙂

---

<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:** [June 28, 2019, 7:52pm UTC](https://discourse.processing.org/t/how-to-save-console-output-as-a-txt-file/12353/15 "2019-06-28T19:52:20Z")

</div>

Hello,

Typo there…

output.print("/n") will print /n

There are the different possible outputs I used testing:

```auto
        //Text file: // Output:
        //output.print("\r"); // CR
        //output.write("\r"); // CR 
        //output.print("\n"); // LF
        //output.write("\n"); // LF
        //output.write("\r\n"); // CRLF        
        //output.print("\r\n"); // CRLF
        //output.print(); // Error! Won't run.
        //output.println(); // CRLF
        //output.print(""); // no output!
        //output.write(""); // no ouput! 
        //output.print("/n"); // /n
        //output.print(":)"); // :)

```

I used Notepad++:  
[https://notepad-plus-plus.org/](https://notepad-plus-plus.org/)  
and select “View \> Show Symbol \> Show all Characters” to see the LF and CR characters (otherwise hidden from view).

🙂
