grazie, mi mancavano InputStream e OutpuStream.
codice:
public class Client {
private final String HOST = "host";
private final int PORT = port;
public static void main(String[] args) {
Client c = new Client();
c.sendFile();
}
private void sendFile() {
try {
Socket socket = new Socket(HOST, PORT);
FileInputStream fis = new FileInputStream(System.getProperty("user.home") + "/booklog.log");
OutputStream out = socket.getOutputStream();
byte[] buf = new byte[1024];
int read;
while ((read = fis.read(buf)) != -1) {
out.write(buf, 0, read);
}
fis.close();
out.close();
} catch (UnknownHostException ex) {
System.out.println(ex.getMessage());
} catch (IOException ex) {
System.out.println(ex.getMessage());
}
}
}
codice:
public class MTManager implements Runnable {
private final String DIR_SAVE = "/media/hd/ftp";
private Socket socket;
public MTManager(Socket socket) {
this.socket = socket;
}
public void run() {
try {
InputStream is = socket.getInputStream();
FileOutputStream fos = new FileOutputStream(new File(DIR_SAVE + "/booklog.log"), true);
byte[] buf = new byte[1024];
int read;
while ((read = is.read(buf)) != -1) {
fos.write(buf, 0, read);
}
fos.close();
is.close();
} catch (Exception e) {
System.out.println(e.getMessage());
} finally {
try {
socket.close();
} catch (IOException e) {
System.out.println(e.getMessage());
}
}
}
}