ok ho capito il concetto, ma ancora alcune incertezze.
ho modificato il client prendendo il tuo link come esempio:
codice:
public class Client {
private final String HOST = "62.94.208.157";
private final int PORT = 9977;
public static void main(String[] args) {
Client c = new Client();
c.sendFile();
}
private void sendFile() {
try {
Socket socket = new Socket(HOST, PORT);
File file = new File(System.getProperty("user.home") + "/booklog.log");
FileInputStream in = new FileInputStream(file);
FileOutputStream out = new FileOutputStream(file);
byte[] buf = new byte[1024];
int read;
while ((read = in.read(buf)) != -1) {
out.write(buf, 0, read);
}
out.flush();
in.close();
} catch (UnknownHostException ex) {
System.out.println(ex.getMessage());
} catch (IOException ex) {
System.out.println(ex.getMessage());
}
}
}
m così nn mi sembra di spedire nulla.
per quanto riguarda il server:
codice:
public void run() {
try {
ObjectInputStream oin = new ObjectInputStream(socket.getInputStream());
File inFile = (File) oin.readObject();
File saveFile = new File(DIR_SAVE + "/" + inFile.getName());
save(inFile, saveFile);
} catch (Exception e) {
System.out.println(e.getMessage());
} finally {
try {
socket.close();
} catch (IOException e) {
System.out.println(e.getMessage());
}
}
}
private void save(File in, File out) throws IOException {
System.out.println(" --ricezione file " + in.getName());
System.out.println(" --dimensione file " + in.length());
FileInputStream fis = new FileInputStream(in);
FileOutputStream fos = new FileOutputStream(out, true);
byte[] buf = new byte[1024];
int i = 0;
while ((i = fis.read(buf)) != -1) {
fos.write(buf, 0, i);
}
fis.close();
fos.close();
System.out.println(" --ricezione completata");
OperationsFile.createLog("Nome file: " + in.getName() + "\nDimensione file: " + in.length());
}
il metodo save prende due file (ingresso e uscita).
quello in ingresso arriva da un ObjectInputStream oin = new ObjectInputStream(socket.getInputStream());
e di inFile legge byte per byte.
quindi nn capisco dove sbaglio, teoricamente è quello che mi hai detto.