qual'è la sintassi del comando?
getFileName o qualcosa di simile?
Questo è il client:
import java.io.*;
import java.net.*;
import javax.swing.*;
public class FileSender {
public static void main( String arg[] )
{
JFileChooser fc = new JFileChooser();
if( fc.showOpenDialog(null) == JFileChooser.APPROVE_OPTION ) {
File tmp = fc.getSelectedFile();
if( JOptionPane.showConfirmDialog(null,"Confermare l'invio del file:\n" + tmp.getName(),"FileSender",JOptionPane.YES_NO_OPTI ON) == JOptionPane.YES_OPTION ) {
try {
sendFile( tmp );
} catch( IOException e ) {
System.out.println( "Si è verificato un errore!" );
}
}
}
System.exit(0);
}
private static void sendFile( File f ) throws IOException
{
System.out.println( "Connessione..." );
Socket s = new Socket( "localhost" , 60000 );
OutputStream out = s.getOutputStream();
FileInputStream in = new FileInputStream( f );
byte buffer[] = new byte[4096];
long totale = 0L;
System.out.println( "Invio file in corso..." );
while( true ) {
try {
int letti = in.read(buffer);
if( letti>0 ) {
out.write( buffer,0,letti );
totale += letti;
} else {
break;
}
} catch( IOException e ) {
break;
}
}
in.close();
out.flush();
out.close();
s.close();
System.out.println( "Invio file terminato [" + totale + " bytes inviati]" );
}
}