-
-
Save kasramp/1ab6998619ce606e7cc6ebd82db7c5f2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.*; | |
import java.util.Vector; | |
import java.io.*; | |
public class Test { | |
public static void main(String[] args) { | |
try { | |
File src = new File(args[0]); | |
File dst = new File(args[1]); | |
test.copyFile(src, dst); | |
System.out.println("File Copied!"); | |
} catch (Exception ex) { | |
ex.printStackTrace(); | |
} | |
} | |
public static void copyFile(File src, File dst) throws IOException { | |
try { | |
InputStream in = new FileInputStream(src); | |
OutputStream out = new FileOutputStream(dst); | |
// Transfer bytes from in to out | |
long expectedBytes = src.length(); // This is the number of bytes we expected to copy.. | |
long totalBytesCopied = 0; // This will track the total number of bytes we've copied | |
byte[] buf = new byte[1024]; | |
int len = 0; | |
while ((len = in.read(buf)) > 0) { | |
out.write(buf, 0, len); | |
totalBytesCopied += len; | |
int progress = (int) Math.round(((double) totalBytesCopied / (double) expectedBytes) * 100); | |
System.out.print(progress + "% "); | |
System.out.print("["); | |
for (int i = 0; i | |
{ | |
System.out.print(">"); | |
} | |
System.out.print("]\r"); | |
} | |
System.out.println(""); | |
in.close(); | |
out.close(); | |
} catch (Exception ex) { | |
ex.printStackTrace(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment