﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>语源科技BlogJava-fuxueliang</title><link>http://www.blogjava.net/fuxueliang/</link><description /><language>zh-cn</language><lastBuildDate>Thu, 30 Apr 2026 06:22:52 GMT</lastBuildDate><pubDate>Thu, 30 Apr 2026 06:22:52 GMT</pubDate><ttl>60</ttl><item><title>java应用程序从网上下载文件</title><link>http://www.blogjava.net/fuxueliang/archive/2006/08/14/63391.html</link><dc:creator>nick</dc:creator><author>nick</author><pubDate>Mon, 14 Aug 2006 01:03:00 GMT</pubDate><guid>http://www.blogjava.net/fuxueliang/archive/2006/08/14/63391.html</guid><wfw:comment>http://www.blogjava.net/fuxueliang/comments/63391.html</wfw:comment><comments>http://www.blogjava.net/fuxueliang/archive/2006/08/14/63391.html#Feedback</comments><slash:comments>6</slash:comments><wfw:commentRss>http://www.blogjava.net/fuxueliang/comments/commentRss/63391.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/fuxueliang/services/trackbacks/63391.html</trackback:ping><description><![CDATA[
		<p>java应用程序与网络通讯一直是我的弱项,想补一补,就从这一篇开始吧!<br />以从网上下载一个图象为例:<br /></p>
		<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee">
				<span style="COLOR: #0000ff">import</span>
				<span style="COLOR: #000000"> java.io.BufferedInputStream;<br /></span>
				<span style="COLOR: #0000ff">import</span>
				<span style="COLOR: #000000"> java.io.BufferedOutputStream;<br /></span>
				<span style="COLOR: #0000ff">import</span>
				<span style="COLOR: #000000"> java.io.File;<br /></span>
				<span style="COLOR: #0000ff">import</span>
				<span style="COLOR: #000000"> java.io.FileOutputStream;<br /></span>
				<span style="COLOR: #0000ff">import</span>
				<span style="COLOR: #000000"> java.io.IOException;<br /></span>
				<span style="COLOR: #0000ff">import</span>
				<span style="COLOR: #000000"> java.net.URL;<br /></span>
				<span style="COLOR: #0000ff">import</span>
				<span style="COLOR: #000000"> java.net.URLConnection;<br /><br /></span>
				<span style="COLOR: #0000ff">public</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">class</span>
				<span style="COLOR: #000000"> DownloadFormURL {<br /><br />    </span>
				<span style="COLOR: #0000ff">public</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">static</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">void</span>
				<span style="COLOR: #000000"> main(String[] args) {<br />        </span>
				<span style="COLOR: #0000ff">try</span>
				<span style="COLOR: #000000"> {<br />            </span>
				<span style="COLOR: #0000ff">new</span>
				<span style="COLOR: #000000"> DownloadFormURL().downloadFile(</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">
						<a href="http://127.0.0.1:8080/image/f.jpg">http://127.0.0.1:8080/image/f.jpg</a>
				</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">, </span>
				<span style="COLOR: #0000ff">new</span>
				<span style="COLOR: #000000"> File(</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">F:/image.jpg</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">));<br />        } </span>
				<span style="COLOR: #0000ff">catch</span>
				<span style="COLOR: #000000"> (IOException e) {<br />            e.printStackTrace();<br />        }<br />    }<br /><br />    </span>
				<span style="COLOR: #0000ff">public</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">void</span>
				<span style="COLOR: #000000"> downloadFile(String sourceURL, File targetFile) </span>
				<span style="COLOR: #0000ff">throws</span>
				<span style="COLOR: #000000"> IOException {<br /><br />        URL url </span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">new</span>
				<span style="COLOR: #000000"> URL(sourceURL);<br />        URLConnection connection </span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> url.openConnection();<br />        java.io.InputStream inputStream </span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> connection.getInputStream();<br />        FileOutputStream outputStream </span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">new</span>
				<span style="COLOR: #000000"> FileOutputStream(targetFile);<br />        BufferedInputStream in </span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">null</span>
				<span style="COLOR: #000000">;<br />        BufferedOutputStream out </span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">null</span>
				<span style="COLOR: #000000">;<br />        </span>
				<span style="COLOR: #0000ff">byte</span>
				<span style="COLOR: #000000"> buffer[] </span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">new</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">byte</span>
				<span style="COLOR: #000000">[</span>
				<span style="COLOR: #000000">8192</span>
				<span style="COLOR: #000000">];<br />        </span>
				<span style="COLOR: #0000ff">try</span>
				<span style="COLOR: #000000"> {<br />            in </span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">new</span>
				<span style="COLOR: #000000"> BufferedInputStream(inputStream, buffer.length);<br />            out </span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">new</span>
				<span style="COLOR: #000000"> BufferedOutputStream(outputStream, buffer.length);<br />            </span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> total </span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">0</span>
				<span style="COLOR: #000000">;<br />            </span>
				<span style="COLOR: #0000ff">for</span>
				<span style="COLOR: #000000"> (</span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> bytesRead </span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">0</span>
				<span style="COLOR: #000000">; (bytesRead </span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> in.read(buffer)) </span>
				<span style="COLOR: #000000">!=</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">-</span>
				<span style="COLOR: #000000">1</span>
				<span style="COLOR: #000000">;) {<br />                out.write(buffer, </span>
				<span style="COLOR: #000000">0</span>
				<span style="COLOR: #000000">, bytesRead);<br />                total </span>
				<span style="COLOR: #000000">+=</span>
				<span style="COLOR: #000000"> bytesRead;<br />            }<br /><br />        } </span>
				<span style="COLOR: #0000ff">finally</span>
				<span style="COLOR: #000000"> {<br />            in.close();<br />            out.close();<br />        }<br />        </span>
				<span style="COLOR: #0000ff">return</span>
				<span style="COLOR: #000000">;<br />    }<br />}<br /></span>
		</div>
		<p>
				<br />
		</p>
		<p>小试了一下,还不错!<img height="19" src="http://www.blogjava.net/Emoticons/emwink.gif" width="19" border="0" /><br /></p>
<img src ="http://www.blogjava.net/fuxueliang/aggbug/63391.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/fuxueliang/" target="_blank">nick</a> 2006-08-14 09:03 <a href="http://www.blogjava.net/fuxueliang/archive/2006/08/14/63391.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>java.beans.PropertyChangeSupport小解！</title><link>http://www.blogjava.net/fuxueliang/archive/2006/07/18/58738.html</link><dc:creator>nick</dc:creator><author>nick</author><pubDate>Tue, 18 Jul 2006 06:02:00 GMT</pubDate><guid>http://www.blogjava.net/fuxueliang/archive/2006/07/18/58738.html</guid><wfw:comment>http://www.blogjava.net/fuxueliang/comments/58738.html</wfw:comment><comments>http://www.blogjava.net/fuxueliang/archive/2006/07/18/58738.html#Feedback</comments><slash:comments>4</slash:comments><wfw:commentRss>http://www.blogjava.net/fuxueliang/comments/commentRss/58738.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/fuxueliang/services/trackbacks/58738.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: java.beans.PropertyChangeSupport是一个实用工具类，支持绑定该属性的bean能够使用该类.当执行setName操作时，会触发firePropertyChange事件， 因为PropertyChangeSupportTest和PropertyChangeSupport绑定,那么在BeanTestListener中，因为添加里支持类的监听器，所以应该触发propertyChange事件， 并且会根据evt.getPropertyName()来获得你在BeanTest中触发事件是绑定的属性名称.........<br>&nbsp;&nbsp;<a href='http://www.blogjava.net/fuxueliang/archive/2006/07/18/58738.html'>阅读全文</a><img src ="http://www.blogjava.net/fuxueliang/aggbug/58738.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/fuxueliang/" target="_blank">nick</a> 2006-07-18 14:02 <a href="http://www.blogjava.net/fuxueliang/archive/2006/07/18/58738.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>我的Blog终于开通了！</title><link>http://www.blogjava.net/fuxueliang/archive/2006/07/17/nick.html</link><dc:creator>nick</dc:creator><author>nick</author><pubDate>Mon, 17 Jul 2006 00:38:00 GMT</pubDate><guid>http://www.blogjava.net/fuxueliang/archive/2006/07/17/nick.html</guid><wfw:comment>http://www.blogjava.net/fuxueliang/comments/58496.html</wfw:comment><comments>http://www.blogjava.net/fuxueliang/archive/2006/07/17/nick.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/fuxueliang/comments/commentRss/58496.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/fuxueliang/services/trackbacks/58496.html</trackback:ping><description><![CDATA[一直想像别的网友一样，在网上尽情挥洒自己的才华，表达自己的喜怒哀乐，记录自己生活的点点滴滴...... 今天，我的blog开通了。首先，当然要祝愿自己一下，希望自己有一个美好的明天！ 同时，也希望广大网友时常光临自己的blog小屋。 ( *_* ) <img src ="http://www.blogjava.net/fuxueliang/aggbug/58496.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/fuxueliang/" target="_blank">nick</a> 2006-07-17 08:38 <a href="http://www.blogjava.net/fuxueliang/archive/2006/07/17/nick.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>