1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
|
public static class RecuperartionFile
{
File file = null;
/**
* Creates a new instance of RecuperartionFile
*/
public RecuperartionFile( URL url )
{
DownloadDlg dlg = new DownloadDlg( null, false );
dlg.setVisible( true );
try
{
URLConnection urlCon = url.openConnection();
dlg.setProgressBar( 50 );
InputStream is = urlCon.getInputStream();
if( is != null )
{
byte[] data = new byte[ 0 ];
byte[] buffer = new byte[ 1024 * 2 ];
int taille;
while( ( taille = is.read( buffer ) ) > 0 )
{
byte[] data2 = new byte[ data.length + taille ];
System.arraycopy( data, 0, data2, 0, ata.length );
System.arraycopy( buffer, 0, data2, data.length, taille );
data = data2;
}
File fichier = new File( System.getProperty( "user.home" ), "img" );
FileOutputStream fos = new FileOutputStream( fichier );
fos.write( data );
fos.flush();
fos.close();
this.file = fichier;
}
} catch( java.io.IOException ex )
{
ex.printStackTrace();
}
dlg.setVisible( false );
}
} |
Partager