Checking the existence of a file

Asked

Viewed 39 times

0

Given a file url:

URL pomUrl = new URL("https://gitlab/grupo/projeto/blob/develop/pom.xml");

How can I verify the existence of a sister file to this?

Something like:

public boolean temIrmao(String pomUrl) {
    if (pomUrl.contains("index.html") return true
    return false;
}
  • Use the exists method()

  • Gabriel, what do you mean by 'brother file'? Would be other files in the same directory?

  • @Joellobo exactly!

1 answer

0

In my research, I have observed that there is the following possibility:

File arquivo = new File("CAMINHO DO ARQUIVO.EXTENSÃO");
if(arquivo.exists()){
    //O ARQUIVO EXISTE - RETORNA TRUE
}else{
    //O ARQUIVO NÃO EXISTE  - CASO RETORNE FALSE
}

You can improve the code for your need by overriding the path and inside the if, checking for the same file with the same name and extension and/or url.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.