A quick and dirty Java Sockets API program:
// imports java.net.Socket, java.io.*
void uploadFile(String hostAddr, int port, String fileName) throws
FileNotFoundException, IOException {
byte[] buf = new byte[1000];
int len = -1;
// connect to host at hostAddr, port
Socket sock = new Socket(hostAddr, port);
FileInputStream in = new FileInputStream(fileName);
OutputStream out = sock.getOutputStream();
while ( ( len = in.read(buf) ) != -1 ) {
out.write(buf, 0, len);
out.flush(); // manually flush output stream for sockets
}
out.close();
sock.close();
in.close();
}
Author: Paul-John A.
// imports java.net.Socket, java.io.*
void uploadFile(String hostAddr, int port, String fileName) throws
FileNotFoundException, IOException {
byte[] buf = new byte[1000];
int len = -1;
// connect to host at hostAddr, port
Socket sock = new Socket(hostAddr, port);
FileInputStream in = new FileInputStream(fileName);
OutputStream out = sock.getOutputStream();
while ( ( len = in.read(buf) ) != -1 ) {
out.write(buf, 0, len);
out.flush(); // manually flush output stream for sockets
}
out.close();
sock.close();
in.close();
}
Author: Paul-John A.
Comments
Post a Comment