• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to download file from www adress to local folder?

 
Imre Ipolyi
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I'm a total beginner with java, so this question may look very easy to answer for you

How can I dowload a picture from the web to a folder on my computer e.g.
the file http://maps.wunderground.com/data/640x480/2xeu_ws_anim.gif
to the folder D:\network ?

Once again, I'm a beginner. Today is the day when I first time used other then simple html code in a file (copy-paste & change a bit) and I didn't know how did I do it but it worked as I wanted
So now I'm glad

Hey, thanx if you answer with The Answer!

Imre
 
Carl Trusiak
Sheriff
Posts: 3341
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Heres a quick and dirty, you can expand on this for something more robust.

 
Imre Ipolyi
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
thanks for the code!
I guess I made a weak try to use it and I did put it in the wrong place so it didn't work.
Does it have to be at least similar to this?

----------------------------------------------------------------------------

<html><head><link rel="stylesheet" href="content_data/prj.css" type="text/css">
<title>Weather Maps Europe</title></head>

<script language="javascript">
try{
URL url = new URL("http://maps.wunderground.com/data/640x480/2xeu_ws_anim.gif");
URLConnection urlConn = url.openConnection();
BufferedInputStream is = new BufferedInputStream(urlConn.getInputStream());
File out = new File("D:\\network", "2xeu_ws_anim.gif");
BufferedOutputStream bout = new BufferedOutputStream(new FileOutputStream(out));
byte[] b = new byte[8 *1024];
int read = 0;
while((read = is.read(b)) > -1){
bout.write(b,0, read);
}
bout.flush();
bout.close();
is.close();

}
catch(IOException mfu){
mfu.printStackTrace();
}
</script>

<body id="contentMerck" leftmargin="0" topmargin="0" background="index_files/content.htm"
bgcolor="#ffffff" link="#cc0000" marginheight="0" marginwidth="0" text="#000000" vlink="#990000">
<div id="content" style="width: 0%; height: 0%;">
<layer name="contentNS"></layer>

<TABLE cellpadding=0 cellspacing=0 border=0>
<TR>
<TD height=256 width=640 valign=top>
<TABLE class=smalltableheader cellspacing=1 cellpadding=0 border =0 width="100%"><TR>
<TD bgcolor="#000080" width="100%">
<font color="#FFFFFF"><b>Europe Wind<BR>
</b></font>
</TD></TR></TABLE>
<center class=smalltableheader>
<b>Click on map for current conditions and forecasts.</b><br>
<A HREF="Wind_anim.html">
<IMG SRC="D:\network\2xeu_ws_anim.gif" BORDER=0
WIDTH=640 HEIGHT=480
ALIGN=TOP ALT="Weather Map" usemap="#IMAGEMAP">
</a>
</TD></TR></TABLE>
</div></body></html>

----------------------------------------------------------------------------

Thanks for the review!
Imre

[ January 31, 2005: Message edited by: Imre Ipolyi ]

[ January 31, 2005: Message edited by: Imre Ipolyi ]
[ January 31, 2005: Message edited by: Imre Ipolyi ]
 
Jeff Bosch
Ranch Hand
Posts: 805
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, Imre -

Welcome to JavaRanch.

Java is not JavaScript. The two are not interchangable! You must compile Java into an Applet if you want to include it in a Web page.

Also, for future posts in which you include code, please be sure to enclose the code in the CODE UBB tags, which are just below the text area where you type your message.
 
Layne Lund
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Jeff Bosch:
You must compile Java into an Applet if you want to include it in a Web page.

This particular problem won't work as an Applet, either. Applets cannot access the local file system. Most likely, you will need to compile this as a Java application instead. You will need to download the Java SDK from http://java.sun.com to do this. However, if you want to do this in JavaScript instead, then you should visit the HTML and JavaScript forum here at the Ranch.

HTH

Layne
 
Jeff Bosch
Ranch Hand
Posts: 805
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, Layne -

I wasn't trying to intimate that the code would work as an applet. My main point was that the code cannot run as a script. Considering the misuse of Java code as though it were JavaScript, I reasoned that going any deeper would be totally lost on Imre.
 
Imre Ipolyi
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Carl, Jeff and Layne,

thanks for your answers, Jeff you are right that it was no sense to go deeper in the explanation when I even didn't know that there was a difference between Java and JavaScript, but it's great that now I know this info and it's also great that Layne told me about the JavaScript forum.
Does JavaScript need some kind of program like SDK or is it used simply like the html code? If it can be used as a simple code in a html file, I'd rather prefer to use JavaScript and not Java. Hmmm... Do I understand right that Java is a programming language like c++ and JavaScript is just an "internet code"?
Are these two very similar to eachother?

Hey, Layne, thanks for the link to the JavaScript forum!
Imre
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic