Results 1 to 8 of 8
  1. #1
    ngc0202 is offline Member
    Join Date
    Jul 2009
    Posts
    32
    Rep Power
    0

    Default Reading a file from the internet?

    Hi everyone, I am currently writing a programme, and I came across an issue. The only solution I saw was to host the required files on my site and have the programme read them from there. The only problem was that I have no idea how to do such a thing. I googled it and I read URL (Java 2 Platform SE v1.4.2) but I was still a bit confused as I had never done anything like this. Can I get an idea of what do to or something to read that will help?
    Support the cause on 10/10/10!
    http://ngc0202.webs.com/thegame.htm

  2. #2
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,272
    Rep Power
    25

    Default

    Does your site have a server that will return the files when they are requested by a client?
    That is the normal job of a server.
    If the server is an HTTP server, then to read a file, you need to issue an HTTP GET request to the server and then read its response.
    Look at the HttpURLConnection and URLConnection classes.
    A Search on the forum will give code samples.

  3. #3
    ngc0202 is offline Member
    Join Date
    Jul 2009
    Posts
    32
    Rep Power
    0

    Default

    No, it wouldn't do anything like that. The programme will know the URL of the file, and I need it to retrieve the data I have in it as it would for a local file.
    Last edited by ngc0202; 09-11-2010 at 06:24 PM. Reason: Grammar mistake.
    Support the cause on 10/10/10!
    http://ngc0202.webs.com/thegame.htm

  4. #4
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,272
    Rep Power
    25

    Default

    I need it to retrieve the data I have in it as it would for a local file.
    What kind of "server" are you using? Can you explain what your setup is?

    To "read" a file from a server, you need to send a request to the server to send you the file.
    One protocol for doing that is HTTP. Another is FTP.

  5. #5
    ngc0202 is offline Member
    Join Date
    Jul 2009
    Posts
    32
    Rep Power
    0

    Default

    There is no server, it just needs to read each line off of a file on the site. Like this: http://kicneoj.webs.com/folder/fornorm.txt the programme does all the stuff it seems this server might. It processes the user input and knows the exact location of the file it needs, I just need it to be able to read it.
    Support the cause on 10/10/10!
    http://ngc0202.webs.com/thegame.htm

  6. #6
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,272
    Rep Power
    25

    Default

    If there is no server, how does the "site" exist? How does any code communicate with the "site" without a server?

    Did you notice that the URL you posted uses the HTTP protocol? See its first 4 letters

    When I "connect" to the URL you have posted above, the server returns this to my program:
    >>>>>> Using URLConnection <<<<<<
    hdr> Date: Sat, 11 Sep 2010 18:23:13 GMT
    hdr> Server: Apache/1.3.39 (Unix) mod_jk/1.2.26 mod_layout/3.2 mod_gzip/1.3.19.1a mod_throttle/3.1.2
    hdr> Last-Modified: Sat, 11 Sep 2010 17:43:16 GMT
    hdr> ETag: "9-4c8bbfb4"
    hdr> Accept-Ranges: bytes
    hdr> Content-Length: 9
    hdr> Keep-Alive: timeout=15, max=80
    hdr> Connection: Keep-Alive
    hdr> Content-Type: text/plain
    like this
    The lines with >hdr are the HTTP response header records. Notice the server identifies itself as Server: Apache/1.3.39
    Last edited by Norm; 09-11-2010 at 07:04 PM.

  7. #7
    ngc0202 is offline Member
    Join Date
    Jul 2009
    Posts
    32
    Rep Power
    0

    Default

    Well, the server doesn't do anything related to the programme, as I don't even have very much control over it. It's all in the programme, except the data that it needs to read off of a page like the one I linked you to.
    Support the cause on 10/10/10!
    http://ngc0202.webs.com/thegame.htm

  8. #8
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,272
    Rep Power
    25

    Default

    To understand how the server works you need to do some research on the HTTP protocol.
    Then read about the two classes I mentioned above and Search for posts on the forum for code samples.

    Believe me there are servers and other bits of software involved in reading data from a site.

Similar Threads

  1. reading a file and writing to a file....help!!!!
    By java_prgr in forum New To Java
    Replies: 3
    Last Post: 07-26-2010, 06:53 PM
  2. Replies: 9
    Last Post: 10-20-2009, 10:52 AM
  3. Replies: 3
    Last Post: 05-09-2009, 11:31 PM
  4. Get a File form internet by URL?
    By makpandian in forum Networking
    Replies: 1
    Last Post: 02-20-2009, 06:48 PM
  5. Replies: 3
    Last Post: 12-09-2008, 08:17 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •