Guest User

Untitled

a guest
Dec 18th, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.41 KB | None | 0 0
  1.       public static void upload( String a, String b, String c, String d, File e, String f ) throws MalformedURLException, IOException
  2.            {
  3.               if (a != null && d != null && e != null)
  4.               {
  5.                  StringBuffer sb = new StringBuffer( "ftp://" );
  6.                  //  On verifie si les variables ne sont pas null.
  7.                  if (b != null && c != null)
  8.                  {
  9.                     sb.append( b );
  10.                     sb.append( ':' );
  11.                     sb.append( c );
  12.                     sb.append( '@' );
  13.                  }
  14.                  sb.append( a );
  15.                  sb.append( '/' );
  16.                  sb.append( d );
  17.                  /*
  18.                   * type ==<; a=ASCII mode, i=image (binary) mode, d= file directory
  19.                   * Ecoute
  20.                   */
  21.                  sb.append( ";type=" + f );
  22.          
  23.                  BufferedInputStream bis = null;
  24.                  BufferedOutputStream bos = null;
  25.                  try
  26.                  {
  27.                     URL url = new URL( sb.toString() );
  28.                     URLConnection urlc = url.openConnection();
  29.                     bos = new BufferedOutputStream( urlc.getOutputStream() );
  30.                     bis = new BufferedInputStream( new FileInputStream( e ) );
  31.                     int i;
  32.                     // lire octet par octet jusqu'à la fin du flux.
  33.                     while ((i = bis.read()) != -1)
  34.                     {
  35.                        bos.write( i );
  36.                     }
  37.                  }
  38.                  finally
  39.                  {
  40.                     if (bis != null)
  41.                        try{bis.close();}
  42.                        catch (IOException ioe){ioe.printStackTrace();}
  43.                     if (bos != null)
  44.                         try{bos.close();}
  45.                        catch (IOException ioe){ioe.printStackTrace();}
  46.                  }
  47.               }
  48.               else
  49.               {
  50.                  System.out.println( "Entrée non disponible." );
  51.               }
  52.            }
  53.         public static void copyFileBuffered(final String currentFile, final String newFile) throws FileNotFoundException, IOException {
  54.             FileInputStream in = new FileInputStream(currentFile);
  55.             try {
  56.                 FileOutputStream out = new FileOutputStream(newFile);
  57.                 try {
  58.                     byte[] byteBuffer = new byte[in.available()];
  59.                     int s = in.read(byteBuffer);
  60.                     out.write(byteBuffer);
  61.                     out.flush();
  62.                 } finally {
  63.                     out.close();
  64.                 }
  65.             } finally {
  66.                 in.close();
  67.             }
  68.         }
Add Comment
Please, Sign In to add comment