![Aplauso](http://static.forosdelweb.com/fdwtheme/images/smilies/aplausos.gif)
![U_U](http://static.forosdelweb.com/fdwtheme/images/smilies/nods.png)
![Silbar](http://static.forosdelweb.com/fdwtheme/images/smilies/silbar.gif)
![dormir](http://static.forosdelweb.com/fdwtheme/images/smilies/durmiendo.png)
MI pagina JSP es esta
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<form method="post" action="ServletCrearTorneo.do">
<input type="file" name="abrir" >
<input type="submit" name="guardar">
</form>
</body>
</html>
MI manejador es este
package org.sistemacampeonato.manejadores;
import java.io.File;
import java.io.IOException;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.nio.channels.FileChannel;
public class Copiar {
private static Copiar instancia;
public static Copiar getInstancia(){
if (instancia == null){
instancia = new Copiar();
}
return instancia;
}
/**
* Copia un solo archivo
* @param s
* @param t
* @throws IOException
*/
public void copyFile(File s, File t)
{
try{
FileChannel in = (new FileInputStream(s)).getChannel();
FileChannel out = (new FileOutputStream(t)).getChannel();
in.transferTo(0, s.length(), out);
in.close();
out.close();
}
catch(Exception e)
{
System.out.println(e);
}
}
}
Mi servlet es este
package org.sistemacampeonato.servlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.ServletException;
import java.io.IOException;
import org.sistemacampeonato.manejadores.Copiar;
import javax.servlet.RequestDispatcher;
import java.io.File;
public class ServletCrearTorneo extends HttpServlet{
public void doPost(HttpServletRequest peticion, HttpServletResponse respuesta) throws IOException, ServletException{
RequestDispatcher despachador = null;
String fichero = peticion.getParameter("abrir");
Copiar cp = new Copiar();
try{
cp.copyFile(new File(fichero), new File("D:\\Users"));
//cp.copy(new File(fichero),new File("C:/Users/CoCo/Desktop/Nueva carpeta"));
System.out.print("Copiado con exito");
}catch(Exception e){
System.out.println(e);
System.out.println("No se pudo Copiar en fichero");
}
despachador = peticion.getRequestDispatcher("pruebas.jsp");
despachador.forward(peticion, respuesta);
}
}