資源簡介
利用Java的Socket實現了文件傳輸功能。
可以傳輸各種大小的文件(KB,MB,GB)。
分為兩個文件:Server和Client,可以直接運行。
代碼片段和文件信息
package?test;
import?java.io.BufferedInputStream;
import?java.io.BufferedOutputStream;
import?java.io.File;
import?java.io.FileInputStream;
import?java.io.IOException;
import?java.net.DatagramPacket;
import?java.net.DatagramSocket;
import?java.net.InetAddress;
import?java.net.Socket;
import?java.net.UnknownHostException;
public?class?Client?{
BufferedOutputStream?bos=null;
BufferedInputStream?bis=null;
String?fileName;
Socket?server;
String?ip;
int?port=-1;
int?len=0;
byte[]?bytes=null;
public?Client(String?fileNameString?ipint?port)?throws?UnknownHostException?IOException{
this.fileName=fileName;
this.ip=ip;
this.port=port;
server=new?Socket(ipport);
this.bytes=new?byte[1024];
bos=new?BufferedOutputStream(server.getOutputStream());
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件????????341??2010-01-13?18:11??readMe.java
?????文件???????1024??2009-08-31?19:57??Server.java
?????文件???????1161??2009-08-31?19:56??Client.java
-----------?---------??----------?-----??----
?????????????????2526????????????????????3
- 上一篇:基于jsp實現的購物車源碼結賬、清空、繼續購物
- 下一篇:Android放大鏡
評論
共有 條評論