Sockety, DataInputStream

0
public void sendFile(File file, DataOutputStream dos) throws IOException {
    if(dos!=null&&file.exists()&&file.isFile())
    {
    	dos = new DataOutputStream(wy);
        FileInputStream input = new FileInputStream(file);
        dos.writeLong(file.length());
        System.out.println(file.getAbsolutePath());
        int read = 0;
        while ((read = input.read()) != -1)
            dos.writeByte(read);
        dos.flush();
        input.close();
        System.out.println("File successfully sent!");
    }
}

W jaki sposób zrobić pobieranie w ten sposób wysłanego pliku?

0
FileOutputStream fos = new FileOutputStream("plik.cos");
DataInputStream dos = new DataInputStream(socket.getInputStream());
long len = dos.readLong();
byte[] buf = new byte[(int)len];
dos.readFully(buf);
fos.write(buf);
fos.flush();
fos.close(); 

1 użytkowników online, w tym zalogowanych: 0, gości: 1