Im trying to delete TXT-files, but I always get the same error message. It's nearly the same code as the one I found on the Internet.
for (int i = 0; i < datei.length; i++)
{
try
{
loeschenDatei = datei[i].delete();
if (loeschenDatei)
{
System.out.println(datei[i] + " wurde geloescht!");
}
else
{
System.out.println(datei[i] + " konnte nicht geloescht werden!");
}
}
catch (IOException ex)
{
ex.printStackTrace();
}
}
I always get the error:
unreachable catch block for ioexception. this exception is never thrown from the try statement body.
This means that nothing within your try block can throw an Exception of type
IOException
. The only thing that I'm unsure of isdatei[i].delete()
. Check out that method signature in your IDE and see if at the end itthrows IOException
or something like that. If that method doesn't throw anything, then remove your try catch block altogether.