File deleting - how?
in
Programming Questions
•
9 months ago
Hi all
A bit of help needed if possible, please.
I have some code where I want to be able to either overwrite a file, or first delete it and then re-write it using saveBytes.
I am using (I think) standard java File code as f.exists() & f.canWrite() both work, but f.delete() doesn't.
Any help or ideas?
- import java.io.*;
- byte[] kickFile ; // to store a loaded wav file
- void setup() {
- // load the wav file
- kickFile = loadBytes("/data/kick.wav");
- // do something to the wav file and then try to re-save
- saveBytes("/data/kick.wav", kickFile );
- // this doesn't work and generates a console error... cannot write the file...
- // ...so try a test... and see if it can be written to and if it will delete
- String fileName = dataPath("/data/kick.wav");
- File f = new File(fileName);
- if (f.exists() && f.canWrite()) { // this works, returning true for both f.exists() and f.canWrite()
- f.delete(); // but this doesn't work... why?
- }
- }
- void draw(){
- }
1