Código Para Enviar Enviar Un Archivo En Java Netbeans
package enviararchivo;
import java.io.*;
import java.net.*;
import javax.swing.JFileChooser;
public class EnviarArchivoCliente {
public static void main(String[] args)
{javax.swing.JFileChooser j= new javax.swing.JFileChooser();
j.showOpenDialog(j);
int seleccion=j.showOpenDialog(j);
String path= j.getSelectedFile().getAbsolutePath();//el entero seleccion verifica el valor de aver presionado aceptar
if (seleccion == JFileChooser.APPROVE_OPTION)
{
//seleccionamos archivo
//Filefichero = j.getSelectedFile();
// y a trabajar con fichero ....
DataInputStream entrada ;
BufferedInputStream bis ;
BufferedOutputStream bos ;int in;
byte [] byteArray;
//Ultima cadena nombre de archivo
//String NombreArchivo = "/ opt/jdk-1.6.bin" ;
String NombreArchivo = "/opt/jdk-1.6.bin" ;
try {
//ultimo archivo n.. archivo local
File archivoLocal = new File(path);
Socket cliente = new Socket ( "localhost" ,1234 );
bis = new BufferedInputStream ( new FileInputStream ( archivoLocal ));
bos = new BufferedOutputStream ( cliente . getOutputStream ());
//Enviamos el Nombre del Archivo
DataOutputStream dos = new DataOutputStream ( cliente.getOutputStream ());
dos.writeUTF ( archivoLocal . getName ());byteArray = new byte [8192];
while(( in = bis.read( byteArray )) != -1 ) {
bos . write ( byteArray , 0 , in );
}
bis .close();bos .close();
} catch ( Exception e ) {
System.err.println ( e );
}
}
}
}
SERVIDOR
package enviararchivo;
import java.io.*;...
Regístrate para leer el documento completo.