Skip to content

Instantly share code, notes, and snippets.

@zubayerahamed
Last active February 7, 2018 14:37
Show Gist options
  • Save zubayerahamed/14eaa7f58ac621621050fe1610f40f52 to your computer and use it in GitHub Desktop.
Save zubayerahamed/14eaa7f58ac621621050fe1610f40f52 to your computer and use it in GitHub Desktop.
How to delete a file in java
import java.io.File;
public class DeleteFile
{
public static void main(String[] args)
{
try{
File file = new File("c:\\logfile20100131.log");
if(file.delete()){
System.out.println(file.getName() + " is deleted!");
}else{
System.out.println("Delete operation is failed.");
}
}catch(Exception e){
e.printStackTrace();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment