Skip to content

Instantly share code, notes, and snippets.

@No-Eul
Created June 16, 2024 12:01
Show Gist options
  • Save No-Eul/da6caaaf783c2930fe4dcb13c99d29a0 to your computer and use it in GitHub Desktop.
Save No-Eul/da6caaaf783c2930fe4dcb13c99d29a0 to your computer and use it in GitHub Desktop.
// This code is made for Rhino JavaScript engine with Java runtime
const FileInputStream = java.io.FileInputStream,
FileOutputStream = java.io.FileOutputStream,
Byte = java.lang.Byte,
JavaArray = java.lang.reflect.Array;
function copyFile(src, dest) {
let inputStream, outputStream;
try {
inputStream = new FileInputStream(src);
outputStream = new FileOutputStream(dest);
let buf = JavaArray.newInstance(Byte.TYPE, 4096), reads;
while ((reads = inputStream.read(buf)) > 0)
outputStream.write(buf, 0, reads);
} catch (e) {
e.printStackTrace();
} finally {
try {
if (!inputStream) inputStream.close();
if (!outputStream) outputStream.close();
} catch (e) {
e.printStackTrace();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment