Results 1 to 8 of 8
- 09-11-2010, 04:44 PM #1
Member
- Join Date
- Jul 2009
- Posts
- 32
- Rep Power
- 0
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
- 09-11-2010, 05:29 PM #2
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.
- 09-11-2010, 06:23 PM #3
Member
- Join Date
- Jul 2009
- Posts
- 32
- Rep Power
- 0
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
- 09-11-2010, 06:49 PM #4
What kind of "server" are you using? Can you explain what your setup is?I need it to retrieve the data I have in it as it would for a local file.
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.
- 09-11-2010, 06:58 PM #5
Member
- Join Date
- Jul 2009
- Posts
- 32
- Rep Power
- 0
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
- 09-11-2010, 07:02 PM #6
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:
The lines with >hdr are the HTTP response header records. Notice the server identifies itself as Server: Apache/1.3.39>>>>>> 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 thisLast edited by Norm; 09-11-2010 at 07:04 PM.
- 09-11-2010, 07:04 PM #7
Member
- Join Date
- Jul 2009
- Posts
- 32
- Rep Power
- 0
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
- 09-11-2010, 07:07 PM #8
Similar Threads
-
reading a file and writing to a file....help!!!!
By java_prgr in forum New To JavaReplies: 3Last Post: 07-26-2010, 06:53 PM -
Reading and Writing the contents of a file to another file
By priyankatxs in forum New To JavaReplies: 9Last Post: 10-20-2009, 10:52 AM -
[SOLVED] how to reading binary file and writing txt file
By tOpach in forum New To JavaReplies: 3Last Post: 05-09-2009, 11:31 PM -
Get a File form internet by URL?
By makpandian in forum NetworkingReplies: 1Last Post: 02-20-2009, 06:48 PM -
How to extract .dat file from the internet using Java?
By burian in forum New To JavaReplies: 3Last Post: 12-09-2008, 08:17 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks