lpr-b:clientupload
no way to compare when less than two revisions
Differenze
Queste sono le differenze tra la revisione selezionata e la versione attuale della pagina.
| — | lpr-b:clientupload [12/10/2007 alle 13:26 (18 anni fa)] (versione attuale) – creata Marco Danelutto | ||
|---|---|---|---|
| Linea 1: | Linea 1: | ||
| + | <code java> | ||
| + | package trasferimentoFile; | ||
| + | import java.io.FileInputStream; | ||
| + | import java.io.FileNotFoundException; | ||
| + | import java.io.IOException; | ||
| + | import java.io.OutputStream; | ||
| + | import java.net.InetAddress; | ||
| + | import java.net.Socket; | ||
| + | import java.net.UnknownHostException; | ||
| + | |||
| + | public class Client { | ||
| + | |||
| + | public static final int MAXBUFFER = 512; | ||
| + | |||
| + | /** | ||
| + | * @param args nomeHostPozzo | ||
| + | */ | ||
| + | public static void main(String[] args) { | ||
| + | |||
| + | String hostname = args[0]; | ||
| + | String filename = args[1]; | ||
| + | InetAddress hostIp = null; | ||
| + | try { | ||
| + | hostIp = InetAddress.getByName(hostname); | ||
| + | } catch (UnknownHostException e) { | ||
| + | System.out.println(" | ||
| + | return; | ||
| + | } | ||
| + | Socket s = null; | ||
| + | try { | ||
| + | s = new Socket(hostIp, | ||
| + | } catch (IOException e) { | ||
| + | System.out.println(" | ||
| + | e.getCause(); | ||
| + | return; | ||
| + | } | ||
| + | FileInputStream fis = null; | ||
| + | try { | ||
| + | fis = new FileInputStream(filename); | ||
| + | } catch (FileNotFoundException e) { | ||
| + | System.out.println(" | ||
| + | return; | ||
| + | } | ||
| + | OutputStream os = null; | ||
| + | try { | ||
| + | os = s.getOutputStream(); | ||
| + | } catch (IOException e) { | ||
| + | System.out.println(" | ||
| + | return; | ||
| + | } | ||
| + | |||
| + | try { | ||
| + | os.write(new String(filename+" | ||
| + | } catch (IOException e) { | ||
| + | System.out.println(" | ||
| + | return; | ||
| + | } | ||
| + | byte [] buffer = new byte[MAXBUFFER]; | ||
| + | int letti = 0; | ||
| + | try { | ||
| + | letti = fis.read(buffer, | ||
| + | } catch (IOException e) { | ||
| + | System.out.println(" | ||
| + | return; | ||
| + | } | ||
| + | while(letti > 0) { | ||
| + | try { | ||
| + | os.write(buffer, | ||
| + | letti = fis.read(buffer, | ||
| + | } catch (IOException e) { | ||
| + | System.out.println(" | ||
| + | return; | ||
| + | } | ||
| + | } | ||
| + | try { | ||
| + | os.close(); | ||
| + | fis.close(); | ||
| + | s.close(); | ||
| + | } catch (IOException e) { | ||
| + | System.out.println(" | ||
| + | return; | ||
| + | } | ||
| + | |||
| + | |||
| + | } | ||
| + | |||
| + | } | ||
| + | </ | ||
lpr-b/clientupload.txt · Ultima modifica: 12/10/2007 alle 13:26 (18 anni fa) da Marco Danelutto
