aspose file tools*
The moose likes Sockets and Internet Protocols and the fly likes reading a file from a url Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Bookmark "reading a file from a url" Watch "reading a file from a url" New topic
Author

reading a file from a url

naveen yadav
Ranch Hand

Joined: Oct 23, 2011
Posts: 384

hi ranchers,

i have this question that suppose there is a site called myVideos.com just like youtube .Is that possible create a java networking program to
get the reference of video files and read them ?

Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

naveen yadav wrote:i have this question that suppose there is a site called myVideos.com just like youtube .Is that possible create a java networking program to
get the reference of video files and read them ?


Yes.
naveen yadav
Ranch Hand

Joined: Oct 23, 2011
Posts: 384

i have written a small java program which copies the code of a web page
have a look.





please suggest few hints how to go about .thanks for reply

Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

naveen yadav wrote:
please suggest few hints how to go about .thanks for reply


What specific problems are you having?
naveen yadav
Ranch Hand

Joined: Oct 23, 2011
Posts: 384

how to get the videos file link form xyz.com? Suppose http://www.youtube.com/watch?v=3POGRbSUPtY" is a link to a video file and when i hit this url it plays the video.
how should i can read this file ?
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

naveen yadav wrote:how to get the videos file link form xyz.com? Suppose http://www.youtube.com/watch?v=3POGRbSUPtY" is a link to a video file and when i hit this url it plays the video.
how should i can read this file ?


Yes, I know that this is what you're trying to do. And I see that you've posted code that shows that you have at least some idea how to go about doing that. Now I am asking you what specific problems you are having.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18570
    
    8

I really wouldn't expect anybody to hack YouTube on the first try. But at any rate I'm pretty sure that YouTube's terms of service don't permit you to just download videos from them. I suggest you should read a site's terms of service before you start trying to download files from that site, and bear in mind that we can't help you to perform acts which might be considered as illegal or piracy on this forum.
Pat Farrell
Rancher

Joined: Aug 11, 2007
Posts: 4658
    
    5

And *after* you have found that its allowable to download the files, why would you want to write code to do it? Use code or programs that someone else has written that are debugged, documented, and tested.

To fetch the contents of a URL, I"d just use wget or curl.

If, for some weird reason, I needed to do it totally within Java, I'd use the Apache HTTP client library.

There is a huge difference between reading a URL's file once, and doing it reliably in production.


naveen yadav
Ranch Hand

Joined: Oct 23, 2011
Posts: 384

i was trying to develop a downloader application from which one can download videos files. There are various applications to do that.
The reason for doing that is i am learning the java networking from quite some time and thought to do some "practical things "
Pat Farrell
Rancher

Joined: Aug 11, 2007
Posts: 4658
    
    5

You may desire to learn some Java networking, but after you have the initial version working, you will spend most of your effort reading RFCs to implement the full protocol.

Rather than doing that, I strongly recommend switching to a pre-existing library
naveen yadav
Ranch Hand

Joined: Oct 23, 2011
Posts: 384

Pat Farrel wrote:I strongly recommend switching to a pre-existing library


are talking of Apache HTTP client library ?

Pat Farrel wrote:
you will spend most of your effort reading RFCs to implement the full protocol.


and how RFC will help me out ?
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18570
    
    8

naveen yadav wrote:i was trying to develop a downloader application from which one can download videos files. There are various applications to do that.
The reason for doing that is i am learning the java networking from quite some time and thought to do some "practical things "


Sure. Learning by doing is an excellent idea. I'm just recommending you do the right things. Like if you were training to become a locksmith, testing your skills by breaking into banks would be the wrong way to go about it.
naveen yadav
Ranch Hand

Joined: Oct 23, 2011
Posts: 384

Paul Clapham wrote:
Sure. Learning by doing is an excellent idea. I'm just recommending you do the right things. Like if you were training to become a locksmith, testing your skills by breaking into banks would be the wrong way to go about it.


well said Paul.
i would appreciate if you can guide me .I am currently reading book Java Network Programming, 3rd Edition, 2004By Elliotte Rusty Harold and java networking tutorial and side by side want to do some practical exercises.
Pat Farrell
Rancher

Joined: Aug 11, 2007
Posts: 4658
    
    5

naveen yadav wrote:
Pat Farrel wrote:I strongly recommend switching to a pre-existing library


are talking of Apache HTTP client library ?


Yes, that is one. There are others.

The point is that making a proper HTTP client is complex and has subtleties that are likely to be missed the first dozen times you try.

You will be reinventing the wheel.
naveen yadav wrote:
Pat Farrel wrote:
you will spend most of your effort reading RFCs to implement the full protocol.


and how RFC will help me out ?


The RFCs define the protocols. You have to implement all of them (or all of the ones related to HTTP) to be able to say your code works.

I wrote my own, years ago before the Apache library was available. I had it in production for six months before it blew up. The data changed from the remote server, and I wasn't supporting the RFC fully.

Let me be clear: as a learning exercise, what you are trying to do is fine.
As a production application, its folly to try to write your own, and a huge waste of time.


#Edited to fix block quote
 
Consider Paul's rocket mass heater.
 
subject: reading a file from a url