# Problems writing to a binary file

**URL:** <https://discourse.processing.org/t/problems-writing-to-a-binary-file/9158>\
**Category:** Coding Questions\
**Created:** [March 9, 2019, 8:39pm UTC](https://discourse.processing.org/t/problems-writing-to-a-binary-file/9158 "2019-03-09T20:39:15Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![xR4yd](https://avatars.discourse-cdn.com/v4/letter/x/e99b99/32.png) [@xR4yd](https://discourse.processing.org/u/xR4yd)\
**Post date:** [March 9, 2019, 8:39pm UTC](https://discourse.processing.org/t/problems-writing-to-a-binary-file/9158/1 "2019-03-09T20:39:15Z")

</div>

I have recently been trying to write to a binary file using following code:

```auto
void exportFile() {
  PrintWriter outFile;
  String out = "";
  outFile = createWriter(outFileName + ".cgespr"); 
  char c = 0;
  outFile.print("cgesprite-file");
  outFile.print((char)xSize);
  outFile.print((char)ySize);
  for (int i = 0; i < xSize * ySize; i++) {
    if (pxls[i] != 16) c = (char)((int)pxls[i] * 16 + 1);
    else c = 0;
    out += c;
  }
  outFile.print(out);
  println(c);
  outFile.flush();
  outFile.close();
}

```

So basically I have this array called pxls and it contains the data which I want to write to the file and it is almost working perfectly but if I open the file with a hex editor, I often see characters 194 or ‘Â’ and 195 or ‘Ã’ which seem to be brought into the file randomly and are causing major problems for my purposes. So my question is: Is there any way not to write this character?

---

<div class="post-metadata">

**Author:** ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)\
**Post date:** [March 10, 2019, 1:50am UTC](https://discourse.processing.org/t/problems-writing-to-a-binary-file/9158/2 "2019-03-10T01:50:07Z")

</div>

try

```auto
void setup() {
  size(200, 200);
}
void draw() {
  println("mouseX "+mouseX+" chr "+char(mouseX));
}

```

and see that might not be what you planned to write
