How to tell why a file deletion fails in Java?

前端 未结 6 1209
忘掉有多难
忘掉有多难 2020-11-27 21:13
File file = new File(path);
if (!file.delete())
{
    throw new IOException(
        \"Failed to delete the file because: \" +
        getReasonForFileDeletionFailur         


        
6条回答
  •  粉色の甜心
    2020-11-27 22:06

    Be aware that it can be your own application that prevents a file from being deleted!

    If you wrote to the file previously and didn't close the writer, you are locking the file yourself.

提交回复
热议问题