diff --git a/FileCopy.java b/FileCopy.java new file mode 100644 index 00000000..aa0c2576 --- /dev/null +++ b/FileCopy.java @@ -0,0 +1,20 @@ +import java.io.*; + +public class FileCopy { + public static void main(String[] args) { + try (InputStream inputStream = new FileInputStream("source.txt"); + OutputStream outputStream = new FileOutputStream("destination.txt")) { + + byte[] buffer = new byte[1024]; + int bytesRead; + + while ((bytesRead = inputStream.read(buffer)) != -1) { + outputStream.write(buffer, 0, bytesRead); + } + + System.out.println("File copied successfully."); + } catch (IOException e) { + e.printStackTrace(); + } + } +}