why this code dont work correct? file a.txt is create on hard disk and then a.txt rename to b.txt but b.txt will not delete.
import java.io.File;
public class Main {
public static void main(String[] args) {
File f=new File("a.txt");
try {
f.createNewFile();
}
catch (Exception e){}
f.renameTo(new File("b.txt"));
f.delete();
}
}
If the line
f.renameTo(new File("b.txt"));
is removed, f.delete();
works correctly and a.txt is deleted from hard disk.