-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClientServer.java
More file actions
44 lines (38 loc) · 1.11 KB
/
ClientServer.java
File metadata and controls
44 lines (38 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package com.socket;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;
class ClientServer {
FileInputStream fin = null;
FileOutputStream fout = null;
InputStream in = null;
OutputStream out = null;
Socket socket;
void receiveFile() throws IOException {
in = socket.getInputStream();
fout = new FileOutputStream("myoutputfile.exe");
int c;
System.out.println("File incoming......");
while((c = in.read()) != -1) {
fout.write(c);
}
System.out.println("Finished");
fout.close();
fout = null;
}
void sendFile() throws IOException {
out = socket.getOutputStream();
fin = new FileInputStream("myinputfile.exe");
int c;
System.out.println("Transferring file...");
while((c = fin.read()) != -1) {
out.write(c);
}
System.out.println("Finished");
fin.close();
fin = null;
}
}