Checking file on web server

2

Next, I have an Android app, this app wants to verify the existence of a web image to be able to load Picasso, if the image does not exist in an address www.algumacoisa.com/img/imagem5.png I will show a message. So what I need is to validate the image before uploading, or trying to upload and if it does not exist inform me so I can define a message. I think it's well explained. Code: // Here I want to check if there is a file at this address: //www.lojaimpacto.com.br/img/foto05.png

if (file exists) {

        iv_xml01_logo = (ImageView) findViewById(R.id.iv_xml01_logo);
        Picasso.with(lista_fones.this)
                .load(www.lojaimpacto.com.br/img/foto05.png)
                .resize(300, 155)
                .centerInside()
                .into(iv_xml01_logo);

} else {

 System.out.println("Arquivo não existe");

}

    
asked by anonymous 17.02.2017 / 15:12

1 answer

1

Method exists() .

Example:

import java.io.*;

public class FileChecker
{    public static void main(String args[])
     {    File f = new File("caminho_para o arquivo");
          if(f.exists())
          {    System.out.println("Arquivo existe");
          }else
          {    System.out.println("Não encontrei, procuro novamente?");
          }
     }
}
    
17.02.2017 / 15:41