J
JayJay
Gast
Hi, passt sie JCopy an die maximale geschwindigkeit an, um Dateien zu kopieren? (Netzwerk, Lokal).
Oder gibt es dafür eine bessere Möglichkeit?
Oder gibt es dafür eine bessere Möglichkeit?
public boolean copyFile( String source, String dest, JProcessFrame frame )
{
try{
long source_filesize = new File( source ).length();
InputStream fis = new FileInputStream( source );
OutputStream fos = new FileOutputStream( dest );
byte buffer[] = new byte[0xffff];
int nbytes=0;
int bytes_read=0;
while( (nbytes = fis.read(buffer)) != -1 )
{
fos.write( buffer, 0, nbytes );
bytes_read += nbytes;
float percentage = ((float)bytes_read / (float)source_filesize)*100.0f;
if( Global.isShutdown ) break;
// set progress-value
frame.setProcessBar( (int)percentage );
}
fis.close();
fos.close();
}catch( Exception e ){
e.printStackTrace();
}
return true;
}