Advertisement
Guest User

Untitled

a guest
Feb 19th, 2019
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.40 KB | None | 0 0
  1. protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  2. // TODO Auto-generated method stub
  3. String nomeFileCaricato=request.getParameter("datafile");
  4. System.out.println("file sorgente:" +nomeFileCaricato);
  5. String[] file=nomeFileCaricato.split("\\\\");
  6. String nomefile = null;
  7. for(int j=0;j<file.length;j++)
  8. nomefile=file[j];
  9.  
  10. boolean risultato;
  11. try {
  12.  
  13. FileInputStream in = new FileInputStream(nomeFileCaricato);
  14. BufferedInputStream br = new BufferedInputStream(in);
  15.  
  16. String path=request.getSession().getServletContext().getRealPath("/");
  17. path="C:\\Documents and Settings\\Administrator\\Desktop\\"+nomefile;
  18.  
  19. System.out.println("file destinazione:" +path);
  20. File fileDestinazione=new File(path);
  21. fileDestinazione.createNewFile();
  22.  
  23.  
  24. FileOutputStream out = new FileOutputStream(fileDestinazione);
  25. BufferedOutputStream bw = new BufferedOutputStream(out);
  26. int lineaLetta;
  27. while ( ( (lineaLetta = br.read()) != -1)) {
  28. //copio nel file di destinazione
  29. bw.write(lineaLetta);
  30. }
  31. br.close();
  32. bw.close();
  33. in.close();
  34. out.close();
  35. risultato=true;
  36.  
  37. }catch(Exception e){
  38. risultato=false; e.printStackTrace();
  39. }
  40.  
  41.  
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement