KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > Get


1 import jcifs.smb.SmbFile;
2 import jcifs.smb.SmbFileInputStream;
3 import java.io.FileOutputStream JavaDoc;
4
5 public class Get {
6
7     public static void main( String JavaDoc argv[] ) throws Exception JavaDoc {
8
9         SmbFile f = new SmbFile( argv[0] );
10         SmbFileInputStream in = new SmbFileInputStream( f );
11         FileOutputStream JavaDoc out = new FileOutputStream JavaDoc( f.getName() );
12
13         long t0 = System.currentTimeMillis();
14
15         byte[] b = new byte[8192];
16         int n, tot = 0;
17         long t1 = t0;
18         while(( n = in.read( b )) > 0 ) {
19             out.write( b, 0, n );
20             tot += n;
21             System.out.print( '#' );
22         }
23
24         long t = System.currentTimeMillis() - t0;
25
26         System.out.println();
27         System.out.println( tot + " bytes transfered in " + ( t / 1000 ) + " seconds at " + (( tot / 1000 ) / Math.max( 1, ( t / 1000 ))) + "Kbytes/sec" );
28
29         in.close();
30         out.close();
31     }
32 }
33
34
Popular Tags