add fileName temporary in the frame selectOutput

When we use selectOutput the field for the name is blank, I wish add the a temporaryName and the extension of the file, but I don't find a simple way to do that. All the track I find is a too complex java solution for me ? Below my idea, but naturally that's don't work :)

void draw() {}

void keyPressed() {
    if(key == 's') selectOutput("Output to save:", "methodSaveCallback");
}

void methodSaveCallback(File selection) {
  if (selection == null) {
    println("Window was closed or the user hit cancel.");
  } else {
    println("User selected " + selection.getAbsolutePath());
  }
}


// the idea
import java.io.File;

public class FileName{
  FileName() throws Exception{
    File f = File.createTempFile("tape_the_name_for_your_file", ".jpg");
    System.out.println(f.getAbsolutePath());
    f.deleteOnExit();
  }
}
Tagged:

Answers

  • edited May 2015 Answer ✓
    void setup() {
      File f1 = new File ("test1.txt");
      selectOutput("Select a file to write to:", 
      "fileSelected", 
      f1);
    }
    
    void fileSelected(File selection) {
      if (selection == null) {
        println("Window was closed or the user hit cancel.");
      } 
      else {
        println("User selected " + selection.getAbsolutePath());
      }
    }
    

    https://processing.org/reference/selectOutput_.html

  • Thx a lot. I don't understand why I don't see this solution before, because my first move it was to go on this page :(

Sign In or Register to comment.