Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void upload( String a, String b, String c, String d, File e, String f ) throws MalformedURLException, IOException
- {
- if (a != null && d != null && e != null)
- {
- StringBuffer sb = new StringBuffer( "ftp://" );
- // On verifie si les variables ne sont pas null.
- if (b != null && c != null)
- {
- sb.append( b );
- sb.append( ':' );
- sb.append( c );
- sb.append( '@' );
- }
- sb.append( a );
- sb.append( '/' );
- sb.append( d );
- /*
- * type ==<; a=ASCII mode, i=image (binary) mode, d= file directory
- * Ecoute
- */
- sb.append( ";type=" + f );
- BufferedInputStream bis = null;
- BufferedOutputStream bos = null;
- try
- {
- URL url = new URL( sb.toString() );
- URLConnection urlc = url.openConnection();
- bos = new BufferedOutputStream( urlc.getOutputStream() );
- bis = new BufferedInputStream( new FileInputStream( e ) );
- int i;
- // lire octet par octet jusqu'à la fin du flux.
- while ((i = bis.read()) != -1)
- {
- bos.write( i );
- }
- }
- finally
- {
- if (bis != null)
- try{bis.close();}
- catch (IOException ioe){ioe.printStackTrace();}
- if (bos != null)
- try{bos.close();}
- catch (IOException ioe){ioe.printStackTrace();}
- }
- }
- else
- {
- System.out.println( "Entrée non disponible." );
- }
- }
- public static void copyFileBuffered(final String currentFile, final String newFile) throws FileNotFoundException, IOException {
- FileInputStream in = new FileInputStream(currentFile);
- try {
- FileOutputStream out = new FileOutputStream(newFile);
- try {
- byte[] byteBuffer = new byte[in.available()];
- int s = in.read(byteBuffer);
- out.write(byteBuffer);
- out.flush();
- } finally {
- out.close();
- }
- } finally {
- in.close();
- }
- }
Add Comment
Please, Sign In to add comment