🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: borland.public.jbuilder.java.api
4 messages
4 total messages Started by Chris Thu, 12 Feb 2004 10:24
How to determine whether a file exist or not in a remote host by using java?
#331
Author: Chris
Date: Thu, 12 Feb 2004 10:24
7 lines
1126 bytes
Howdy,

I want to confirm if  there is a file in a romote machine, 
How could I do using Java?

TIA
Regards.
Re: How to determine whether a file exist or not in a remote host by using java?
#342
Author: John
Date: Fri, 27 Feb 2004 11:02
3 lines
1360 bytes
If you know the URL of the file you could try using  the exists() method
from the File Class, maybe?
This method returns a boolean indicating if the File exists.
Re: How to determine whether a file exist or not in a remote host by using java?
#292
Author: Scott
Date: Sat, 03 Apr 2004 16:37
42 lines
2380 bytes
Chris,

I think you'd have to have something running on the remote machine to answer
the question "Does /this file/ exist?".

Some ideas come to mind:

* If the remote machine has an ftp or http server running, and the server
has access to the directory, you could do something in java to query those
servers.  With http, for example, if the file's not there you'd get a 404
error header back.

* If you've got a webserver running asp, cold fusion, servlets, etc, you
could write something in one of those languages that was a bit more tailored
to your requirements.  does_file_exist.cfm?filename=this_file could return a
simple Yes or No back to you...no need to examine 404 headers, etc.

* Write a server in Java that accepted the remote request, looked for the
file and responded.  There is a lot of sample code out there showing how to
implement network servers in Java (often in the threads chapter of a java
tutorial).  Yours would just respond to the question "Does /this file/
exist?"

* Java's RMI (remote method invocation) might be suitable, but I'm way out
of my depth on how it works to say what to do.

Hope this helps.

Scott



"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.
>
Re: How to determine whether a file exist or not in a remote host by using java?
#294
Author: 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.
>
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads