A java program that isn't behaving as it should be... please help.

I am trying to get the following code to work but it isn't playing ball.
I basically want it to download the file from the following url:
http://www.ecb.int/stats/eurofxref/eurofxref.zip
But all this seems to do is create the empty zip...
Could someone please let me know why they think this is not downloading the actual zip?
import java.io.*;
import java.net.*;
* Command line program to download data from URLs and save
* it to local files. Run like this:
* java FileDownload http://schmidt.devlib.org/java/file-download.html
* @author Marco Schmidt
public class FileDownload {
     public static void download(String address, String localFileName) {
          OutputStream out = null;
          URLConnection conn = null;
          InputStream  in = null;
          try {
               URL url = new URL(address);
               out = new BufferedOutputStream(
                    new FileOutputStream(localFileName));
               conn = url.openConnection();
               in = conn.getInputStream();
               byte[] buffer = new byte[1024];
               int numRead;
               long numWritten = 0;
               while ((numRead = in.read(buffer)) != -1) {
                    out.write(buffer, 0, numRead);
                    numWritten += numRead;
               System.out.println(localFileName + "\t" + numWritten);
          } catch (Exception exception) {
               exception.printStackTrace();
          } finally {
               try {
                    if (in != null) {
                         in.close();
                    if (out != null) {
                         out.close();
               } catch (IOException ioe) {
     public static void download(String address) {
          int lastSlashIndex = address.lastIndexOf('/');
          if (lastSlashIndex >= 0 &&
              lastSlashIndex < address.length() - 1) {
               download(address, address.substring(lastSlashIndex + 1));
          } else {
               System.err.println("Could not figure out local file name for " +
                    address);
     public static void main(String[] args) {
          for (int i = 0; i < args.length; i++) {
               download(args<i>);

Hello Mendez,
it is hard to say what the problem is in your case, but my guess is that you are trying to download from some location where you don't normally connect to the internet directly but access URLs via a proxy server.
In that case you would have to replace the fourth line in the try-block with code like this
conn = url.openConnection(new Proxy(Proxy.Type.HTTP,
                                    new InetSocketAddress("<proxyHostName>", <proxyPort>)));
where proxyHostName and proxyPort will have to be set to the values that apply to you.
Let me know if this works. If it doesn't, do you get any error message?
Regards,
Jens

Similar Messages

  • HT5312 algokar Dec 26, 2013 2:11 AM Forgot Answer Questions safety tried to re-send a lot of email did not reach any messages to re-ask safety   I can not buy any program that I forgot to ask him answer safety   Please help and send me a re-liquefaction a

    Forgot Answer Questions safety tried to re-send a lot of email did not reach any messages to re-ask safety
    I can not buy any program that I forgot to ask him answer safety
    Please help and send me a re-liquefaction answer to the same email

    1)  Apple ID: All about Apple ID security questions
    If necessary
    2)  See Here... ask to speak with the Account Security Team...
    Apple ID: Contacting Apple for help with Apple ID account security
    3)  Or Email Here  >  Apple  Support  iTunes Store  Contact

  • How to make a Java program that recognises a function of two variables...

    How to make a Java program that recognises a function of two variables to assign values to that?
    First I will give an example and then do the question.
    Ex1.
    We have any function, eg.y = x ^ 2 + 1 (read 'y' equals 'x' high to the square), a function of the second degree.
    To build the graph of this function attach values to 'x' to find the values of 'y'
    And thus mount the pair ordered (x, y) which represents a point on the Cartesian plane.
    Assigning values to 'x' 'we can build up a table that gives us the pairs ordered:
    We can use any numbers, but arfer interval [-3.3]
    X | y = x ^ 2 + 1
    -3 | Y = (-3) ^ 2 +1 = 10
    -2 | Y = (-2) ^ 2 +1 = 5
    -1 | Y = (-1) ^ 2 +1 = 2
    0 | y = (0) ^ 2 +1 = 1
    1 | y = (1) ^ 2 +1 = 2
    2 | y = (2) ^ 2 +1 = 5
    3 | y = (3) ^ 2 +1 = 10
    We then ordered the pairs:
    (-3.10), (-2.5); (-1.2), (0,1), (1,2), (2,5), (3,10)
    Tabem that can be represented by a table:
    X | y
    -3 | Y = 10
    -2 | Y = 5
    -1 | Y = 2
    0 | y = 1
    1 | y = 2
    2 | y = 5
    3 | y = 10
    Now I begin to explain my doubts.
    See this program:
    Ex2
    * To change this template, choose Tools | Templates
    * And open the template in the editor.
    Encontrando_o_valor_de_y package;
    * @ Author des Soldat Gottes
    Import javax.swing.JOptionPane;
    Public class (Main
    * @ Param args the command line arguments
    Public static void main (String [] args) (
    Int x, y;
    String x1;
    X1 = JOptionPane.showInputDialog ( "We have the function y = x + 1 \ n" +
    "Assign a value for 'x',"); / / receives a value for the function y = x + 1
    X = Integer.parseInt (x1); / / tranforma String in int
    Y = x + 1; / / receives the value of 'x' and calculates' y '
    JOptionPane.showMessageDialog (null, "The value of 'y' is: \ t \ t" + y);
    / / Displays the value of 'y'
    System.exit (0);
    We see that the program receives above a value for 'x' and replaces the function contained in the program, y = x + 1, and so is the value of the variable 'y'.
    In: x1 = JOptionPane.showInputDialog ( "We have the function y = x + 1 \ n" +
    "Assign a value for 'x',");
    The entry is a number and that number is assigned aa ja existing function in the (y = x + 1).
    The question is: would it be possible to come to a function?
    Ex: the program ask: DIGITE THE FUNCTION?
    The USUARIO DIGITARIA A FUNCTION ANY, TYPE: y = x ^ 2 +1
    The program would recognize the function and give numerical values to that function as Ex1, at the beginning of this text.
    And then to find the values of the x and y launch a table.
    It would be possible that?
    By invez of entering with a number so that the program sustitua a function ja existing as Ex2, seen above, entering with a function quaquer (type: y = x ^ 2 +1) for the program atribuisse values to that function and then create a table of values as Ex1.
    I hope it has been easier to understand my doubts now.
    Thank you for your attention!
    God bless!

    rafaelmenezes wrote:
    Thanks for the explanation, could understand what fly said.
    But as it applied to a program?
    How to create a program that recognizes that the entry coefficients?Are you asking about how to parse out the coefficients from the string "3x^4 + 4x^3 - 8x^2 + 5x^1 + 2x^0"? If you define the format to strictly follow that example, this should get you started:
    Strip out the spaces
    Split the String on "x^"
    That should give you [3, 4+4, 3-8, 2+5, 1+2, 0]
    Split each resulting String on "+ | -", preserving the operator as a token so you can apply the correct sign to the coeff.
    That should leave you with [3, 4, +, 4, 3, -, 8, 2, +, 5, 1, +, 2, 0]. Every other number is a coeff, the rest are the degrees.
    You can strip out the +, since those coeffs are already positive, and strip out the - after negating the following number. This is all assuming that you have to write this yourself. There is no doubt already a library or 5 out there that does this for you.

  • Creating java program that orders 3 numbers in ascending order using if els

    Does anyone know what code to use for creating a java program that uses the if else operators to order 3 variables in ascending order?

    nar0122 wrote:
    correct on the homework assumption...you have a good nose...the thing is...i know i need to make an if statement saying if a is less than b, and a is less than c...print a first...but how do i get it to "print a" first? if a is less than c and b...and so on for b and c? sorry if that was confusing...
    int a = ..., b = ..., c = ...;
    if(a > b AND a > c) {
      print a
      if(b > c) {
        print b, print c
      } else {
        print c, print b
    etc.

  • Java program that create a graphic interface of the WGET program

    Hello,
    How can I make a Java program that create a graphic interface of the WGET program.
    Please post something already developed.
    No Applet.
    Thank you.

    You can use java.lang.Runtime.exec or java.lang.ProcessBuilder to execute external programs like wget. Generally you pass one of those methods an array of Strings; the first String is the name of the executable, and the rest are arguments. You get a Process object that represents the running process that you've started; you can get standard input and output streams from that Process to read output. This is probably stuff your teacher already told you...but if not, hope it helps.
    You should read this article about pitfalls around Runtime.exec:
    http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html
    Much of the information there also applies to ProcessBuilder.
    Good luck on your homework.

  • I want to write a java program that can add a user to a role or sub role to the Profile Database in iPlanet Portal Server 3.0. Does anyone has any idea or a sample program do such thing. Thanks, Tommy

    I want to write a java program that can add a user to a role or sub role to the Profile Database in iPlanet Portal Server 3.0. Does anyone has any idea or a sample program do such thing? Thanks, Tommy

    // create the user profile, get the handle back,
    // and set the membership profile attributes.
    ProfileAdmin newProfile = null;
    try {
    // the users profile name is the domain      
    // he belongs to plus their userName
    // you will request.domain if your doing this from a servlet, domain_name is the domain_name the user belongs too
    String profileName = domain_name + "/" + user;
         if (debug.messageEnabled()) {
    debug.message("creating profile for " + profileName);
    // create the user profile object
    newProfile = ProfileManager.createProfile(
    getSession(), profileName ,Profile.USER);
    UserProfile userProfile = (UserProfile)newProfile;
         // set the role the user is a member of. Default is to set
         // the users to the default role of the domain they surfed to
         StringBuffer roleName = new StringBuffer(64);
    // request.domain instead of domain_name if your doing this from a servlet ..
    Profile dp = getDomainProfile(domain_name);
    roleName.append(dp.getAttributeString("iwtAuth-defaultRole"));
         if (debug.messageEnabled()) {
    debug.message("setting role for " + user + " = " + roleName);
    userProfile.setRole(roleName.toString());
    newProfile.store(false);
    } catch (ProfileException pe) {
         debug.error("profile exception occured: ",pe);
    return;
    } catch (ProfileException pe) {
         debug.error("login exception occured: ",le);
    return;
    HTH ..

  • Hello ive been trying to get this matter token care of for the past 24 hrs and still no help im getting very upset now I paid 100 plus $$ to have this program that isn't even working I would like to speak to someone about on the phone I got a 1800 number

    hello ive been trying to get this matter token care of for the past 24 hrs and still no help im getting very upset now I paid 100 plus $$ to have this program that isn't even working I would like to speak to someone about on the phone I got a 1800 number for tech but everytime I call it hangs up and says to chat........ ive been doing that all day yesterday its kinda getting old telling the same thing over n over again so I would like some real live help a number I can call or someone can call me 402 802 1211 everytime I try to do something on this it ask for my serial num I put it in and it says invalid number and when I do my pics it has trail across them

    Hi,
    I'm sorry to hear that you are having problems but this is a user to user forum and only occasionally visited by Adobe staff. Depending on your version of Photoshop elements, you may be able to get help through the chat sessions starting here
    https://helpx.adobe.com/uk/contact.html?promoid=KLXNA
    If you give us details like your operating system, Photoshop elements version and the problem you ae having, someone may well be able to help you.
    Brian

  • Writing java program that uses UMTS service

    Hi
    I wonder if it is possible to write java programs that use UMTS services. Is there any class-package in java related with UMTS services?

    you can call a batch file using NT service. the batch file executes the java program. and you can also send an email thru that java program.

  • I have an iPhone 4s just eight months, it is normal that the battery lasts only 3 hours? please help me thank you very much.

    I have an iPhone 4s just eight months, it is normal that the battery lasts only 3 hours? please help me thank you very much.

    Three hours if definitely NOT normal. I get at least 48 hours out my 2 year old iPhone 4S' battery with light usage. Did you do the iOS 7 update on the phone it self (OTA) or through iTunes? In my experience most problems are caused by the OTA updates. For this reason I ALWAYS update using iTunes on my computer.
    I would suggest restoring your phone using iTunes on your computer and setting it us as a new phone. This downloads a fresh copy of iOS 7.1 from Apple and installs it on your phone. Just make sure that you transfer all purchased items (apps, music, etc.) as well as photos to your computer before restoring as the restore will completely wipe your phone. Do not restore from a back-up. Yes, you will loose all your data on the phone but restoring a back-up can restore the problem you are currently having back to your phone. Once your phone has been restored you can manually sync back your apps and music.
    Before restoring you can also check to see that battery-killers like Location Services, Background App Refresh, etc are only turned on for the apps that really need it. I recently read and article that said that the Facebook app can be a real battery killer. If you have this app installed turn of location services and background app refresh for this app and see if that helps. Also go to Settings / General / Restrictions / Location Services / System Services and turn off all the options in that menu. Your phone does not need any of those to function. Constantly using your phone's GPS is a huge battery killer. I only have Location Services enabled for Find my iPhone and Background App Refresh is turned off completely.
    I hope this helps.

  • HT1338 When I try to link my Macbook to my TV, I cannot find the "Arrangement" button that would lead me to "Mirror Display". Please help!

    When I try to link my Macbook to my TV, I cannot find the "Arrangement" button that would lead me to "Mirror Display". Please help!

    The Arrangement tab only appears in System Preferences Displays pane if a second display is recognized by the system (the OS).  So it seems like your MacBook is not seeing the TV as being connected.
    Describe the video connection between MacBook and TV...  What type of video out port does your MacBook model have?  How is it converted to the type of port used on the TV?

  • My iphone 4 is taking forever to sync...I let it sync all night and only completed about 1/4 of of the songs downloaded. Apps seem to be fine. I have tried restoring it and that didn't do anything. Can someone please help?

    My iphone 4 is taking forever to sync...I let it sync all night and only completed about 1/4 of of the songs downloaded. Apps seem to be fine. I have tried restoring it and that didn't do anything. Can someone please help?

    how many songs are syncing cuz i only have at most 200 or so and it takes a while so it might be how many songs are syncing to the device

  • I am looking for macbookpro mid 2010 HDD exact specs so that i can upgrade it to 1TB. PLEASE HELP ME  about OEM apple brand or which one is better.Thanks

    I am looking for macbookpro mid 2010 HDD exact specs so that i can upgrade it to 1TB. PLEASE HELP ME  about OEM apple brand or which one is better?.Thanks

    clintonfrombirmingham Your information is not correct.
    http://kb.sandisk.com/app/answers/detail/a_id/8142/~/difference-between-sata-i,- sata-ii-and-sata-iii
    I have a sata II samsung 5400 rpm and i am only able to transfer at 85 read right speed.
    On my main drive sata III ocz agility 3 ssd i get 120 mb read and 180 write.
    Neither of these come close to the 300 mb promised. So it wont matter if he got sata II or III
    The speed came from Blackmagic Disk Speed Test

  • Good evening I would please help me, IGood evening I would please help me, I have problems with flash player when update on my computer Flash Player for windows 8, gives me error in the installation that is not apply on my computer. Please help. Thank You

    Good evening I would please help me, IGood evening I would please help me, I have problems with flash player when update on my computer Flash Player for windows 8, gives me error in the installation that is not apply on my computer. Please help. Thank You

    First, confirm that ActiveX Filtering is configured to allow Flash content:
    https://forums.adobe.com/thread/867968
    Internet Explorer 11 introduces a number of changes both to how the browser identifies itself to remote web servers, and to how it processes JavaScript intended to target behaviors specific to Internet Explorer. Unfortunately, this means that content on some sites will be broken until the content provider changes their site to conform to the new development approach required by modern versions of IE.
    You can try to work around these issues by using Compatibility View:
    http://windows.microsoft.com/en-us/internet-explorer/use-compatibility-view#ie=ie-11
    If that is too inconvenient, using Google Chrome may be a preferable alternative.

  • My iPad shut down on its own and when i switched it on, it asks to 'Activate iPad' and reads below 'This iPad was lost and erased. Sign in with the Apple ID that was used to erase this iPad". Please help!!!!

    my iPad shut down on its own and when i switched it on, it asks to 'Activate iPad' and reads below 'This iPad was lost and erased. Sign in with the Apple ID that was used to erase this iPad". Please help!!!!

    Is it possible that you or someone who knows your iCloud sign on went into the Find My iPhone app and erased your device via iCloud? Because that is what that message is saying.
    Have you tried to sign on with your Apple ID and password?
    Was it online prior to this incident happening?
    GB

  • I am unable to register my debit card after creating my apple ID. Whenever i click enter after filling all the debit card details, it shows that, "your payement method has been declined". Please help me people, why is it so.?

    I am unable to register my debit card after creating my apple ID. Whenever i click "continue" after filling all the debit card details, it shows that, "Your payement method has been declined". Please help me people, why is it so.? Also, i would ike to tell that my bank is, Union Bank Of India and it facilitates the auto conversion, rupee to dollar.. I think there is a different problem. Please help me guys.!!

    The card must be issued in the same country as the store you are trying to use. If you're trying to sign up for the US Apple Store, it must be a US card with a US billing address. If you're trying to sign up in India, it must be an Indian card with an Indian billing address.
    Apple will run a small charge, which will be credited back, to make sure the card is valid. If it is a debit card and you do not have enough in the account to cover the authorization, it will be declined.
    It is possible the currency conversion you mentioned may be causing a problem. Contact the issuing bank if you are sure you have enough in the account and you are signing up for the correct store.

Maybe you are looking for

  • How to clear open items?

    when i click the process open items button for clearing out standings in (f-28) after raise the sales invoice , message seems after click the process open items " the entry(2222 company code) missing table t043g).... let me know what happen and what

  • Ipod Nano dosen't show what is song plaing now .

    Ipod Nano dosen't show what is song plaing now and volume.I see only empty display.I have reinstalled my iPod,iTunes software and reseted settings in my Ipod.But i have the same problem.Please halpe me. Fujitsu Siemens   Windows XP  

  • Combining items with different fields

    I have users that want to built a report that shows all the products in the same table. Problem is certain fields will only be populated for certain products. For example, a table with 15 fields, first 5 are constant across both products, 2nd 5 only

  • Lens correction for Hasselblad V series lenses

    Lightroom does not provide lens correction for Hasselbald V series lenses, e.g. Carl Zeiss Planar 2,8/80. Hasselblad Phocus program does but Lightroom ignores Phocus metadata in FFF files imports. Is there any posssibility to achieve lens correction

  • How do you remove redeye automatically using iPhoto?

    Hi, Is it possible and if so how do you remove red eye automatically from a batch of pictures, using iPhoto. In Adobe Photoshop Elements 4 (for windows) there is a feature that allows to remove redeye automatically, as they are dowloaded from the cam