Skip to content

Instantly share code, notes, and snippets.

@kasramp
Created August 4, 2020 17:57
Show Gist options
  • Save kasramp/1ab6998619ce606e7cc6ebd82db7c5f2 to your computer and use it in GitHub Desktop.
Save kasramp/1ab6998619ce606e7cc6ebd82db7c5f2 to your computer and use it in GitHub Desktop.
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