From 16d27984058115707240f3797c8aa6a32e8cae4d Mon Sep 17 00:00:00 2001 From: InderMangal <80519267+InderMangal@users.noreply.github.com> Date: Fri, 22 Oct 2021 19:21:29 +0530 Subject: [PATCH] Read the content of an input file and write it in output --- java/main.java | 29 +++++++++++++++++++++++++++++ java/sourcefile.txt | 3 +++ 2 files changed, 32 insertions(+) create mode 100644 java/main.java create mode 100644 java/sourcefile.txt diff --git a/java/main.java b/java/main.java new file mode 100644 index 0000000..f3701da --- /dev/null +++ b/java/main.java @@ -0,0 +1,29 @@ +import java.io.*; +public class Main { + public static void main( + String[] args) throws IOException + { + + FileInputStream sourceStream = null; + FileOutputStream targetStream = null; + + try { + sourceStream + = new FileInputStream("sourcefile.txt"); + targetStream + = new FileOutputStream("targetfile.txt"); + + int temp; + while (( + temp = sourceStream.read()) + != -1) + targetStream.write((byte)temp); + } + finally { + if (sourceStream != null) + sourceStream.close(); + if (targetStream != null) + targetStream.close(); + } + } +} \ No newline at end of file diff --git a/java/sourcefile.txt b/java/sourcefile.txt new file mode 100644 index 0000000..cf187ab --- /dev/null +++ b/java/sourcefile.txt @@ -0,0 +1,3 @@ +Object-oriented programming is a programming paradigm based on the concept of "objects", +which can contain data and code: data in the form of fields, and code, in the form of procedures. +A feature of objects is that an object's own procedures can access and often modify the data fields of itself. \ No newline at end of file