Ayushman Bhattcharya - MCAN - 293 - Java Assignment4
Ayushman Bhattcharya - MCAN - 293 - Java Assignment4
BHATTACHARYA
STREAM- MCA
SEM.- 2ND.
BATCH—2022-24
ROLL-13071022022
PAPER CODE-
MCAN-293 JAVA
ASSIGNMENT 4
1. code: -
javaapplication11:-
FileWriteExample:
import java.io.FileWriter;
import java.io.IOException;
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author DELL
*/
public class FileWriteExample {
public static void main(String[] args) {
String fileName = "C:\\File\\File4.txt";
try (FileWriter writer = new FileWriter(fileName)) {
writer.write("Object Oriented Programming world.\n");
writer.write("Java is Object Oriented Programming Language.\n");
writer.write("Java is Platform independent language\n");
writer.write("Java supports Multithreading. Java virtual machine is
important.");
System.out.println("File written successfully.");
} catch (IOException e) {
System.err.println("Error writing to file: " + e.getMessage());
}
}
}
Output: -
File view:
2. code:-
javaapplication16:-
counts.java:
import java.util.Scanner;
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author DELL
*/
public class counts {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
String input;
try ( // TODO code application logic here
Scanner scanner = new Scanner(System.in)) {
System.out.println("Enter a string: ");
input = scanner.nextLine();
}
Output:
3. code:-
javaapplication10:-
FileReaderExample:
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
Text file:
Output:
4. code:-
javaapplication10:-
FileReaderExample:
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
Output:-
5. code:-
javaApplication10:
FileReaderExample:
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author DELL
*/
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
class FileWordCounter {
private String fileName;
Output:
6. code:-
javaApplication10:
FileReaderExample:
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author DELL
*/
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
class FileWordFrequencyCounter {
private final String fileName;
Output:-
7. code:-
javaApplication11:
FileReaderExample:
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author DELL
*/
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
class FilePatternSearcher {
private String fileName;
Output:
8. code:-
javaApplication11:
FileScannerExample:
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author DELL
*/
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
Output:
9. code:
javaApplication11:
FileCopyExample:
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author DELL
*/
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
Output:
10. code:-
javaApplication11:
student.java:
import java.io.*;
import java.util.ArrayList;
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author DELL
*/
public class Student implements Serializable {
private final String name;
private final int rollNumber;
private final int marks;
private final String year;
@Override
public String toString() {
return "Name: " + name + ", Roll Number: " + rollNumber + ", Marks: " + marks
+ ", Year: " + year;
}
public static void main(String[] args) {
ArrayList<Student> students = new ArrayList<>();
students.add(new Student("Asutosh", 1001, 85, "2022"));
students.add(new Student("Bikash", 1002, 92, "2022"));
students.add(new Student("Chaaru", 1003, 78, "2023"));
students.add(new Student("Damini", 1004, 90, "2023"));
students.add(new Student("Eshani", 1005, 80, "2024"));
Output: