Created
June 16, 2024 12:01
-
-
Save No-Eul/da6caaaf783c2930fe4dcb13c99d29a0 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
// 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