0


Hi,
i written a code for delete particular file which it was saved in some folder "temp" which it was shown in the below.


try{

    java.io.File objFile = new java.io.File("F:/temp/FirstPdf-022.pdf");

    objFile.delete();

 } catch(Exception e) {

}

In the above code, i delete the file "FirstPdf-022.pdf". But i need delete all the files dynamically. If any one know the code, pls let me know.

Edited by jt86442: n/a

3
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by NormR1
1


Hi,
i written a code for delete particular file which it was saved in some folder "temp" which it was shown in the below.


try{

    java.io.File objFile = new java.io.File("F:/temp/FirstPdf-022.pdf");

    objFile.delete();

 } catch(Exception e) {

}

In the above code, i delete the file "FirstPdf-022.pdf". But i need delete all the files dynamically. If any one know the code, pls let me know.

//...
File file = new File("F:/temp");
if ( !file.canRead() ) {
   throw new IOException("Cannot list temp directory");
}

for ( String directoryEntry : file.list() ) {
   File toDelete = new File ( file.getAbsolutePath().concat( File.pathSeparator ).concat( directoryEntry );
   if ( toDelete.canWrite() ) {
      toDelete.delete();
   }
}

file.close();
//...

Edited by nikelin: n/a

0

i need delete all the files dynamically

Sounds like you need to get the names of all the files in the directory and delete them one by one. Read the comments in the above code.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.