Prośba o wytłumaczenie - kopiowanie pliku

0

Natrafiłem na taki tutorial jak skopiować pliki.


public class CopyFile
{
    public static void main(String[] args)
    {	
 
    	InputStream inStream = null;
	OutputStream outStream = null;
 
    	try{
 
    	    File afile =new File("Afile.txt");
    	    File bfile =new File("Bfile.txt");
 
    	    inStream = new FileInputStream(afile);
    	    outStream = new FileOutputStream(bfile);


 //od
    	    byte[] buffer = new byte[1024];
 
    	    int length;
    	  
    	    while ((length = inStream.read(buffer)) > 0){
 
    	    	outStream.write(buffer, 0, length);
 
    	    }
//do
 
    	    inStream.close();
    	    outStream.close();
 
    	    System.out.println("File is copied successful!");
 
    	}catch(IOException e){
    		e.printStackTrace();
    	}
    }
} 

Proszę o wytłumaczenie co się dzieje w zaznaczonym fragmencie między innymi dlaczego buffer ma rozmiar 1024.

0

Spytaj autora kodu dlaczego akurat 1024.

Rozmiar bufora   Czas kopiowania (ms).
         128                  2139,7
         512                  1220,3
        1024                  1138,9
        4096                  1120,9
       10000                   684,4
      100000                   459,7

Kopiowany plik miał około 38 mB.

1 użytkowników online, w tym zalogowanych: 0, gości: 1