# \[Processing 3\] Unable to Delete Files in /data through Java.io.File

**URL:** <https://discourse.processing.org/t/processing-3-unable-to-delete-files-in-data-through-java-io-file/11693>\
**Category:** Coding Questions\
**Created:** [May 29, 2019, 8:58pm UTC](https://discourse.processing.org/t/processing-3-unable-to-delete-files-in-data-through-java-io-file/11693 "2019-05-29T20:58:04Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ILikePi](https://avatars.discourse-cdn.com/v4/letter/i/7ab992/32.png) [@ILikePi](https://discourse.processing.org/u/ILikePi)\
**Post date:** [May 29, 2019, 8:58pm UTC](https://discourse.processing.org/t/processing-3-unable-to-delete-files-in-data-through-java-io-file/11693/1 "2019-05-29T20:58:04Z")

</div>

This is the code… I think the issue is how I am using Java.io.File but I have no idea.

```auto
String str = new Integer(i).toString();
        String fileName1 = dataPath(str+".csv");
        File f1 = new File(fileName1);
        String fileName2 = dataPath("arr"+str+".JSON");
        File f2 = new File(fileName2);
        String fileName3 = dataPath("player"+str+".JSON");
        File f3 = new File(fileName3);
        if (f1.exists()){
          f1.delete();
          f2.delete();
          f3.delete();
       }

```

Even without

```auto
  if (f1.exists()){
         
       }

```

It does not do anything

If I check if it deleted (without exists either) , through

```auto
if (f1.delete()){
}

```

It still comes out false.

Anyone’s contribution is highly appreciated!

---

<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:** [May 30, 2019, 2:04am UTC](https://discourse.processing.org/t/processing-3-unable-to-delete-files-in-data-through-java-io-file/11693/2 "2019-05-30T02:04:30Z")

</div>

did you suggest/check that

- the directory /data/ exists ( or expect that it is created? )
- the file exists already at /data/filename  
( or that it is created by that code? )

– but your code does not create anything here  
( win7 64bit / processing 3.5.3. )  
otherwise,  
if i create the path and file manually,  
the used file exists and delete functions work just fine.

* * *

next time you paste code please

just play/post for one fix test filename  
( and not with 3 created filenames )

and make it a short but RUNnable code

* * *

here the full way, with directory and file creation  
what is somehow useless as processing can not use existing empty files for append?  
more a academic exercise

```auto
String fileName = "test.txt", fullfileName, fullpathName;
File newp, newf;
boolean pathok, fileok;

void setup() {
  fullpathName = dataPath("");
  newp = new File(fullpathName);
  pathok = newp.exists();
  println("path : "+fullpathName+" found: "+pathok);
  if ( !pathok ) { 
    newp.mkdir();
    println("dir created");
  }
  fullfileName = dataPath(fileName);
  newf = new File(fullfileName);
  fileok = newf.exists();
  println("file : "+fullfileName+" found: "+fileok);
  if ( !fileok ) 
  try { 
    newf.createNewFile();
    println("file created");
  }
  catch(IOException e) {
    throw new IllegalStateException(e);
  }
}

void draw() {
}

void keyPressed() {
  if ( key =='d' ) {
    if ( newf.exists() ) {
      print("file exists,");
      newf.delete();
      println(" now deleted!");
    }
  }
}

```

the program structure allows you to check ( by file manager )  
if path and file exists,  
and then press ‘d’  
and check again.

---

<div class="post-metadata">

**Author:** ![ILikePi](https://avatars.discourse-cdn.com/v4/letter/i/7ab992/32.png) [@ILikePi](https://discourse.processing.org/u/ILikePi)\
**Post date:** [May 30, 2019, 7:20pm UTC](https://discourse.processing.org/t/processing-3-unable-to-delete-files-in-data-through-java-io-file/11693/3 "2019-05-30T19:20:59Z")

</div>

Thank you for the help, I agree that I should’ve only used one filename for the question.
