From bd256464452d0b8f2ed1fbfc3a25d3ac82c97359 Mon Sep 17 00:00:00 2001 From: Kavyapriya Date: Sun, 26 Mar 2023 20:50:07 +0530 Subject: [PATCH] Submitting ex 7 for review --- Task-7 File IO/contentsFile | 1 + Task-7 File IO/copy.txt | 3 + Task-7 File IO/dateStore.txt | Bin 0 -> 46 bytes Task-7 File IO/details | 3 + Task-7 File IO/file5 | 0 Task-7 File IO/file6 | 0 Task-7 File IO/file_new | 0 Task-7 File IO/lineByLineCopy.txt | 3 + .../src/__1__CountNoOfCharacters.java | 16 +++++ Task-7 File IO/src/__2__CountNoOfWords.java | 16 +++++ Task-7 File IO/src/__3__FileOperations.java | 64 ++++++++++++++++++ Task-7 File IO/src/__4__ListContents.java | 15 ++++ .../src/__5__ImageByteByByteCopy.java | 21 ++++++ Task-7 File IO/src/__6__FileViewer.java | 14 ++++ Task-7 File IO/src/__7__CopyCharByChar.java | 19 ++++++ .../src/__8__CopyFileLineByLine.java | 32 +++++++++ .../src/__9__SerializeAndDeserialize.java | 30 ++++++++ 17 files changed, 237 insertions(+) create mode 100644 Task-7 File IO/contentsFile create mode 100644 Task-7 File IO/copy.txt create mode 100644 Task-7 File IO/dateStore.txt create mode 100644 Task-7 File IO/details create mode 100644 Task-7 File IO/file5 create mode 100644 Task-7 File IO/file6 create mode 100644 Task-7 File IO/file_new create mode 100644 Task-7 File IO/lineByLineCopy.txt create mode 100644 Task-7 File IO/src/__1__CountNoOfCharacters.java create mode 100644 Task-7 File IO/src/__2__CountNoOfWords.java create mode 100644 Task-7 File IO/src/__3__FileOperations.java create mode 100644 Task-7 File IO/src/__4__ListContents.java create mode 100644 Task-7 File IO/src/__5__ImageByteByByteCopy.java create mode 100644 Task-7 File IO/src/__6__FileViewer.java create mode 100644 Task-7 File IO/src/__7__CopyCharByChar.java create mode 100644 Task-7 File IO/src/__8__CopyFileLineByLine.java create mode 100644 Task-7 File IO/src/__9__SerializeAndDeserialize.java diff --git a/Task-7 File IO/contentsFile b/Task-7 File IO/contentsFile new file mode 100644 index 0000000..fc5a27f --- /dev/null +++ b/Task-7 File IO/contentsFile @@ -0,0 +1 @@ +weailufkwbakugkqvdwqku \ No newline at end of file diff --git a/Task-7 File IO/copy.txt b/Task-7 File IO/copy.txt new file mode 100644 index 0000000..b47eb93 --- /dev/null +++ b/Task-7 File IO/copy.txt @@ -0,0 +1,3 @@ +Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. +It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. +It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum. \ No newline at end of file diff --git a/Task-7 File IO/dateStore.txt b/Task-7 File IO/dateStore.txt new file mode 100644 index 0000000000000000000000000000000000000000..38f02b7dc2c3ce6f20e680a2701a98bef8ee1aa5 GIT binary patch literal 46 zcmZ4UmVvdnh=DIFu`E%qv?Mb}&n2-WH6yE$(L1t4l9_>_qM)3Efq}7Iu4=ko1ps6Z B4j2Fc literal 0 HcmV?d00001 diff --git a/Task-7 File IO/details b/Task-7 File IO/details new file mode 100644 index 0000000..b47eb93 --- /dev/null +++ b/Task-7 File IO/details @@ -0,0 +1,3 @@ +Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. +It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. +It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum. \ No newline at end of file diff --git a/Task-7 File IO/file5 b/Task-7 File IO/file5 new file mode 100644 index 0000000..e69de29 diff --git a/Task-7 File IO/file6 b/Task-7 File IO/file6 new file mode 100644 index 0000000..e69de29 diff --git a/Task-7 File IO/file_new b/Task-7 File IO/file_new new file mode 100644 index 0000000..e69de29 diff --git a/Task-7 File IO/lineByLineCopy.txt b/Task-7 File IO/lineByLineCopy.txt new file mode 100644 index 0000000..5f775a0 --- /dev/null +++ b/Task-7 File IO/lineByLineCopy.txt @@ -0,0 +1,3 @@ +Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. +It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. +It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum. diff --git a/Task-7 File IO/src/__1__CountNoOfCharacters.java b/Task-7 File IO/src/__1__CountNoOfCharacters.java new file mode 100644 index 0000000..8927ae2 --- /dev/null +++ b/Task-7 File IO/src/__1__CountNoOfCharacters.java @@ -0,0 +1,16 @@ +import java.util.Scanner; + +public class __1__CountNoOfCharacters { + public static void main(String[] args) { + + try(Scanner scanner = new Scanner(System.in); ){ + String inputString = scanner.nextLine(); + + char[] inputStringCharacters = inputString.toCharArray(); + System.out.println("No of characters recieved via System input : "+inputStringCharacters.length); + + }catch(Exception e) { + System.out.println(e); + } + } +} diff --git a/Task-7 File IO/src/__2__CountNoOfWords.java b/Task-7 File IO/src/__2__CountNoOfWords.java new file mode 100644 index 0000000..04099ef --- /dev/null +++ b/Task-7 File IO/src/__2__CountNoOfWords.java @@ -0,0 +1,16 @@ +import java.util.Scanner; + +public class __2__CountNoOfWords { + public static void main(String[] args) { + + try(Scanner scanner = new Scanner(System.in); ){ + String inputString = scanner.nextLine(); + + String[] inputStringWords = inputString.split(" "); + System.out.println("No of words recieved via System input : "+inputStringWords.length); + + }catch(Exception e) { + System.out.println(e); + } + } +} \ No newline at end of file diff --git a/Task-7 File IO/src/__3__FileOperations.java b/Task-7 File IO/src/__3__FileOperations.java new file mode 100644 index 0000000..005b101 --- /dev/null +++ b/Task-7 File IO/src/__3__FileOperations.java @@ -0,0 +1,64 @@ +import java.util.Scanner; +import java.io.File; + +class FileOperations { + Operations operation; + public Operations getAction() { + return operation; + } +} + +abstract class Operations{ + public abstract void operate(File file); +} + +class DeleteAFile extends Operations{ + public void operate(File file) { + if(file.exists()){ + file.delete(); + System.out.println("File deleted successfully.."); + }else{ + System.out.println("File not found..."); + } + } +} + +class RenameAFile extends Operations{ + public void operate(File file) { + if(file.exists()){ + Scanner scanner = new Scanner(System.in); + System.out.print("Enter the new name for your file - "); + String name = scanner.nextLine(); + scanner.close(); + if(file.renameTo(new File(name))){ + System.out.println("File renamed to "+name+" successfully.."); + }else { + System.out.println("Error occured.."); + } + }else{ + System.out.println("File not found..."); + } + } +} + +class SizeOfFile extends Operations{ + public void operate(File file) { + if(file.exists()){ + System.out.println("Size of file : "+ file.length()); + }else{ + System.out.println("File not found..."); + } + } +} + +public class __3__FileOperations { + public static void main(String[] args) throws Exception { + File file = new File("file5"); + + FileOperations fop = new FileOperations(); + fop.operation = (Operations) Class.forName("RenameAFile").newInstance(); + fop.getAction().operate(file); + + } + +} diff --git a/Task-7 File IO/src/__4__ListContents.java b/Task-7 File IO/src/__4__ListContents.java new file mode 100644 index 0000000..b963870 --- /dev/null +++ b/Task-7 File IO/src/__4__ListContents.java @@ -0,0 +1,15 @@ +import java.io.File; + +public class __4__ListContents { + public static void main(String[] args) { + + File path = new File(System.getProperty("user.dir")+"/src"); + + System.out.println("No of files and directories in this path are : "+path.list().length+"\n"); + + for(int i=0;i