473,797 Members | 3,196 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

File not getting downloaded from internet.

dmjpro
2,476 Top Contributor
Here is my code

Expand|Select|Wrap|Line Numbers
  1.  
  2. import java.io.BufferedInputStream;
  3. import java.io.BufferedOutputStream;
  4. import java.io.FileOutputStream;
  5. import java.net.InetAddress;
  6. import java.net.InetSocketAddress;
  7. import java.net.Proxy;
  8. import java.net.SocketAddress;
  9. import java.net.URL;
  10.  
  11. /*
  12.  * To change this template, choose Tools | Templates
  13.  * and open the template in the editor.
  14.  */
  15. import java.net.URLConnection;
  16.  
  17. /**
  18.  *
  19.  * @author Admin
  20.  */
  21. public class SWfDowloader {
  22.     public static void main(String a[]) throws Exception{
  23.         String swf_path = "http://www.prototypejs.org/assets/2008/1/25/prototype-1.6.0.2.js";
  24.         URL swf_url = new URL(swf_path);
  25.         byte address[] = {(byte)144,(byte)16,(byte)192,(byte)245};
  26.         SocketAddress socket_address = new InetSocketAddress(InetAddress.getByAddress(address),8080);
  27.         Proxy proxy = new Proxy(Proxy.Type.HTTP,socket_address);
  28.         URLConnection url_conn = swf_url.openConnection(proxy);
  29.         url_conn.connect();
  30.         BufferedInputStream swf_in_stream = new BufferedInputStream(url_conn.getInputStream());
  31.         FileOutputStream swf_file = new FileOutputStream("d:/test.js");
  32.         BufferedOutputStream swf_out_stream = new BufferedOutputStream(swf_file);
  33.         byte bytes[] = new byte[512];
  34.         int read_bytes = 0;
  35.         while((read_bytes=swf_in_stream.read(bytes))!=-1){
  36.             System.out.println(read_bytes);
  37.             swf_out_stream.write(bytes, 0,read_bytes);
  38.         }
  39.         swf_in_stream.close();
  40.         swf_file.close();
  41.         swf_out_stream.close();
  42.     }
  43. }
  44.  
The file is not getting downloaded properly some parts left at the end what should i do?
Apr 7 '09 #1
2 2017
JosAH
11,448 Recognized Expert MVP
You're closing the FileOutputStrea m before you're closing the wrapping BufferedOutputS tream so something could have been in that buffer that could not be flushed to the wrapped file stream. Close the BufferedOutputS tream first (it will close the wrapped stream for you).

kind regards,

Jos
Apr 7 '09 #2
dmjpro
2,476 Top Contributor
Wow what an experience ;)
The file now getting downloaded properly.
But if i want to download video stream then will my code help that?
"http://s.ytimg.com/yt/swf/watch-vfl87635.swf" this is my link.
Actually file is downloaded but it's now playing properly, no video is coming ;)

Actually what happens if i put the URL of that JS file then the content comes on the browser, but if i put the video URL then no video stream is coming.
What would be the procedure to download the video stream in this case?
Apr 7 '09 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

10
2854
by: Steve | last post by:
Hi all i am just starting to get back into VB and i need a little help. I am writing a program that asks a user to type in a set of numbers/letters (in this case shipping containers). Once the data is entered i have my 4 letters and i want to be able to call up data relating to the 4 letters. Basically i want it to show who the container belongs to and any other data i wish to put in there relating to the container.
2
2309
by: Frostillicus | last post by:
I'm trying to get an ASP to return a zip file to the remote browser from an Image (BLOB) field in SQL Server 2000 but Internet Explorer keeps saying: Cannot open C:\Documents and Settings\Frostillicus\Local Settings\Temporary Internet Files\Content.IE5\U7GXENGF\file.zip The URL to open the zip file is like this: doc_view.asp?id=1&ver=2 ....where id and ver represent the zip file's version in the database. The code I've pieced...
12
2596
by: A.M. | last post by:
Hi at all, how can I do to insert into a HTML page a file .txt stored in the same directory of the server where is the html file that must display the text file.txt? Thank you very much P.Pietro
4
6253
by: Drew | last post by:
I have been looking all over the web for an example of how to accomplish this. I am trying to download a comma seperated file from a https server. I can't establish the connection - the error reads System.Net.WebException: The underlying connection was closed: Could not establish secure channel for SSL/TLS. ---> System.ComponentModel.Win32Exception: The function completed successfully, but must be called again to complete the contex Here...
3
3872
by: Jocelyn Duhaylungsod | last post by:
I have been getting the following server errors sporadically while downloading excel, csv or xml file. Internet Explorer cannot download <file name> from <IP address> "The server returned an invalid or unrecognized response" / "The connection with the server was reset" I'm using Response.BinaryWrite to send down the file content as attachment (sample codes is attached below). I read some of the similar posts in the newsgroup about the...
1
5402
by: Roy | last post by:
Hi, I have a problem that I have been working with for a while. I need to be able from server side (asp.net) to detect that the file i'm streaming down to the client is saved completely/succsessfully on the client's computer before updating some metadata on the server (file downloaded date for instance) However, All examples i have tried, and all examples I have found that other people says works - doesn't work for me :-(
6
3746
by: Sushil Prasad | last post by:
I am having problem in displaying the compiled help file. In asp.net app I have link button labeled help. On the users click of this button i do the respose.redirect to the url of the .chm file. The error message on the web page i get is Action Cancelled. I do see the left panel of help file that has the contents. The right panel is the one that is not appearing. Also this help file does display and work well when i browse it from the...
0
1303
by: makinha | last post by:
Hello All, I can use WebClient.DownloadFile Method to download target file from the website, like WebClient.DownloadFile("http://www.abc.com/a.pdf", "D:\a.pdf") but how can I verify the file is exactly the same as the source file? For example, when we try to download some big files from the internet e.g. Win XP - service pack 2, the IE download windows may sometime report download completed and terminate the download process, but...
1
47492
KevinADC
by: KevinADC | last post by:
Note: You may skip to the end of the article if all you want is the perl code. Introduction Many websites have a form or a link you can use to download a file. You click a form button or click on a link and after a moment or two a file download dialog box pops-up in your web browser and prompts you for some instructions, such as “open” or “save“. I’m going to show you how to do that using a perl script. What You Need Any recent...
0
9685
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10469
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10209
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10023
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7560
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6803
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5459
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4135
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2934
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.