🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.api
Article #294

Re: How to determine whether a file exist or not in a remote host by using java?

#294
From: Scott
Date: Sat, 03 Apr 2004 16:58
43 lines
2268 bytes
Chris,

I found this snippet on the web, which shows how you could ask a remote web
server if a URL was available.  It's from
http://www.rgagnon.com/javadetails/java-0059.html

This would only help if the remote file was accessible as a URL.
import java.net.*;
import java.io.*;
import java.net.*;

public class Check {

public static void main(String s[]) {
    System.out.println(exists("http://www.rgagnon.com/howto.html"));
    System.out.println(exists("http://www.rgagnon.com/pagenotfound.html"));
   }

static boolean exists(String URLName){
  try {
    HttpURLConnection.setFollowRedirects(false);
    // note : you may also need
    //        HttpURLConnection.setInstanceFollowRedirects(false)
    HttpURLConnection con =
       (HttpURLConnection) new URL(URLName).openConnection();
    con.setRequestMethod("HEAD");
    return (con.getResponseCode() == HttpURLConnection.HTTP_OK);
    }
  catch (Exception e) {
       e.printStackTrace();
       return false;
       }
  }
 }"Chris" <wangguoqian@totyusoft.com> wrote in message
news:402b53b2$1@newsgroups.borland.com...
> Howdy,
>
> I want to confirm if  there is a file in a romote machine,
> How could I do using Java?
>
> TIA
> Regards.
>
Technical Details
Message-ID: <406eed91$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!news.glorb.com!news.tele.dk!news.tele.dk!small.news.tele.dk!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail
References: <402b53b2$1@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 1089d0,160816a85b795761
X-Google-Attributes: gid1089d0,public
X-Google-ArrivalTime: 2004-04-03 09:10:00 PST
Reply-To: "Scott" <scotthpowell@yahoo.com>
From: "Scott" <scotthpowell@yahoo.com>
Newsgroups: borland.public.jbuilder.java.api
References: <402b53b2$1@newsgroups.borland.com>
Subject: Re: How to determine whether a file exist or not in a remote host by using java?
Date: Sat, 3 Apr 2004 11:58:47 -0500
Lines: 45
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
NNTP-Posting-Host: 24.239.150.17
Message-ID: <406eed91$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1081011601 24.239.150.17 (3 Apr 2004 09:00:01 -0800)
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!news.glorb.com!news.tele.dk!news.tele.dk!small.news.tele.dk!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail