Java file to delete itself from the system.
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
/**
* Below file will delete itself from the system when executed.
* @author Nitin
*
*/
public class FileDelete {
public static void main(String[] args) throws IOException {
String parent = System.getProperty("user.dir");
String str = FileDelete.class.getCanonicalName();
str = str.replace('.', '\\');
str = str + ".java";
System.out.println(str);
Path path = Paths.get(parent, "src\\", str);
System.out.println(path.toString());
Files.delete(path);
}
}
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
/**
* Below file will delete itself from the system when executed.
* @author Nitin
*
*/
public class FileDelete {
public static void main(String[] args) throws IOException {
String parent = System.getProperty("user.dir");
String str = FileDelete.class.getCanonicalName();
str = str.replace('.', '\\');
str = str + ".java";
System.out.println(str);
Path path = Paths.get(parent, "src\\", str);
System.out.println(path.toString());
Files.delete(path);
}
}