Java - INPUT FILE

 
Vista:

INPUT FILE

Publicado por Juanma (1 intervención) el 21/12/2009 20:31:29
Buenas

Tengo una aplicacion con netbeans, en JSP y JAVA.

La cuestion es, mediante un Input File, quiero que el archivo escogido, se copie a otro directorio o se suba al servidor, me da = cual de las dos cosas.

Mi jsp actual tiene

Input file
Input text
Input button, onclick Funcion()

La funcion termina aciendo un submit, que con un getcontextpath, te lleva a la clase .java que maneja los datos.

Del Input file UNICAMENTE consigo obtener el nombre del archivo, y no la ruta del mismo.

Mi problema esta O en conseguir la ruta de ese archivo,
O en subirlo al servidor o a donde sea.. y desde esa ruta ya manejarlo yo a mi antojo.

UN saludo !
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder

RE:INPUT FILE

Publicado por jroker (1 intervención) el 20/02/2010 03:14:26
public class CopyMachine {

public static void copyFile( String copiar, String Lugar ) throws FileNotFoundException, IOException {

File inputFile = new File( copiar );
File pegar = new File( Lugar );

byte[] buffer = new byte[1024];

int byteContador;


FileInputStream in = new FileInputStream( inputFile );
FileOutputStream pegard = new FileOutputStream( pegar );

do {
byteContador = in.read( buffer );
if ( byteContador > 0 ) {
pegard.write( buffer, 0, byteContador );
}
} while ( byteContador != -1 );

in.close();
pegard.close();


}

public static void main( String[] args ) throws FileNotFoundException, IOException {
// display a file dialog to the user for file selection



FileDialog fd = new FileDialog( new Frame(), "Choose a file to copy...", FileDialog.LOAD );
fd.setDirectory( "\\" );
fd.show();
if ( fd.getFile() != null ) {
String sourceFile = fd.getDirectory() + fd.getFile();

fd.setTitle( "Select destination..." );
fd.setMode( FileDialog.SAVE );
fd.show();
if ( fd.getFile() != null ) {
String destinationFile = fd.getDirectory() + fd.getFile();
copyFile( sourceFile, destinationFile );
}
}

System.exit( 0 );
}

}
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar