File Check on Web Server

Asked

Viewed 47 times

2

Next, I have an Android app, this app wants to check the existence of an image on the web to be able to load by Picasso, if the image does not exist in a www.somemacoisa.com/img/imagem5.png I will show a message. So what I need is to validate the image before loading, or try to load and if there is no informing me so I can set a message. I think that’s pretty 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");

}

  • You can edit your answer and put the code you are using on the server and also tell where the image is?

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?");
          }
     }
}
  • Thanks. But this method is not checking on the server. What should I do?

  • What do you mean ? Put in the code you’re trying to ...

  • I think he means the app’s rootpath

  • Well let’s see... There’s already a crowd looking at it now only depends on it...

  • File file = new File(this.getExternalFilesDir(Environment.DIRECTORY_PICTURES), "http://lojaimpacto.com.br/guia/img/empresas/logo/img_508.png"); if (file.exists()) { System.out.println("Exists"); } Else { System.out.println("Does not exist"); }

  • File file = new File("http://lojaimpacto.com.br/guia/img/empresas/logo/img_508.png"); if (file.exists()) { System.out.println("It exists"); } Else { System.out.println("It does not exist"); }

  • All the way as if there isn’t one

  • I have to check because the image can be either as PNG or JPG. And to call Picasso I have to indicate which extension.

Show 3 more comments

Browser other questions tagged

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