Problems writing to a binary file

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

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?

1 Like

try

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

and see that might not be what you planned to write

1 Like