javs Socket传压缩文件,并文件打开接收到的文件
javs Socket传压缩文件,并文件打开接收到的文件
public class TranFileServer {
public static void main(String[] args){
ServerSocket server;
Socket st;
try {
server = new ServerSocket(4000);
st = server.accept();
File receivedfile = new File( "src/2.rar ");
BufferedInputStream bin = new BufferedInputStream(st.getInputStream());
FileOutputStream fout = new FileOutputStream(receivedfile);
int i = bin.read();
while(i != -1){
fout.write(i);
i = bin.read();
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
客户端:
public class TranFileClient {
public static void main(String[] args){
try {
Socket st = new Socket( "localhost ",4000);
File f = new File( "2.rar ");
FileInputStream fin = new FileInputStream(f);
BufferedOutputStream bout = new BufferedOutputStream(st.getOutputStream());
int size = fin.available();
for(int i = 0;i < size; i++){
bout.write(fin.read());
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
补充:Jsp教程,J2ME开发