Edit character in text file

i need to write some data, how do i edit a single character in a text file?

-Grim

Hi Grimtin10,
In order to interact with text files, you should use loadStrings() and saveStrings(). Check out the reference here:
https://processing.org/reference/loadStrings_.html
loadStrings() saves a text file that is in your sketch folder to an array of Strings. If you know where the character you want to change is, go in to that array, change the character, and then save the String array using saveStrings(). You can save it under the same name if you want to overwrite the original file.
Best of luck.

  • Trilobyte

Here’s an example how to save some stuff (ie game score):

int xpos;
int ypos;
boolean[] keys = {false, false, false, false};

void setup(){
  fullScreen();
  loadStuff();
}

void draw(){
  background(0);
  
  if(keys[0]){
    ypos -= 5;
  }
  if(keys[1]){
    ypos += 5;
  }
  if(keys[2]){
    xpos += 5;
  }
  if(keys[3]){
    xpos -= 5;
  }
  
  rect(xpos, ypos, 50, 50);
}

void keyPressed(){
  switch(keyCode){
    case UP:
    keys[0] = true;
    break;
    case DOWN:
    keys[1] = true;
    break;
    case RIGHT:
    keys[2] = true;
    break;
    case LEFT:
    keys[3] = true;
    break;
  }
}

void keyReleased(){
  switch(keyCode){
    case UP:
    keys[0] = false;
    break;
    case DOWN:
    keys[1] = false;
    break;
    case RIGHT:
    keys[2] = false;
    break;
    case LEFT:
    keys[3] = false;
    break;
  }
}

// Save if we exit the sketch
void exit(){
  saveStuff();
  super.exit();
}

// This is what you're looking for
void loadStuff(){
  try{
    String[] stuff = loadStrings(System.getProperty("user.home") + File.separator + "stuff.txt");// Can be any file type
    xpos = int(stuff[0]);
    ypos = int(stuff[1]);
  }catch(Exception e){
    println("File doesn't exist!");
  }
}

void saveStuff(){
  String[] stuff = {str(xpos), str(ypos)};
  saveStrings(System.getProperty("user.home") + File.separator + "stuff.txt", stuff);
}