You are on page 1of 25

Chat Log      C:\Users\chira\Documents\ChatLog Refresher Program _Java Full stack

_ C Programming _ Python_ _Batch1_ Virtual Training at NEC 2021_10_08 13_04.rtf

Monica (to Everyone): 09:28: import java.io.*;


public class ConsoleInput {
public static void main(String args[]) throws IOException    {
      InputStreamReader isr = new InputStreamReader(System.in);
      BufferedReader br = new BufferedReader(isr);
      System.out.println("Enter Your Employer Name:");
      String name = br.readLine();
      System.out.println("Enter Your Basic Salary:");
      String salary1 = br.readLine();
      int salary2 = Integer.parseInt(salary1);
      System.out.println("Enter Your House Rent:");
      String rent1 = br.readLine();
      double rent2 = Double.parseDouble(rent1);
      System.out.println("Your name is " + name);
      System.out.println("Your Total Salary is " + (salary2+rent2));
}
}

shivendra gupta (to Everyone): 09:29: Enter Your Employer Name:


abc
Enter Your Basic Salary:
90000
Enter Your House Rent:
10000
Your name is abc
Your Total Salary is 100000.0

APURV AGNIHOTRI (to Everyone): 09:29: Enter Your Employer Name:


abc
Enter Your Basic Salary:
100
Enter Your House Rent:
200
Your name is abc
Your Total Salary is 300.0
Harthik Ps (to Everyone): 09:29: Enter Your Employer Name:
abc
Enter Your Basic Salary:
1000000
Enter Your House Rent:
10000
Your name is abc
Your Total Salary is 1010000.0

Shikhar Shukla (to Everyone): 09:30: Enter Your Employer Name:


Enter Your Basic Salary:
Enter Your House Rent:
Your name is Shikhar
Your Total Salary is 210.0

Naveen Kumar Mittal (to Everyone): 09:30: Enter Your Employer Name:
naveen
Enter Your Basic Salary:
28000
Enter Your House Rent:
10000
Your name is naveen
Your Total Salary is 38000.0

Akshay Singh (to Everyone): 09:30: Enter Your Employer Name:


Akshay Singh
Enter Your Basic Salary:
3000
Enter Your House Rent:
2000
Your name is Akshay Singh
Your Total Salary is 5000.0

Ravi Pratap (to Everyone): 09:30: Enter Your Employer Name:


abc
Enter Your Basic Salary:
90000
Enter Your House Rent:
10000
Your name is abc
Your Total Salary is 100000.0
Shipra Yadav (to Everyone): 09:30: Enter Your Employer Name:
abc
Enter Your Basic Salary:
90000
Enter Your House Rent:
10000
Your name is abc
Your Total Salary is 100000.0

Syed Ali Abbas (to Everyone): 09:30: Enter Your Employer Name:
okay
Enter Your Basic Salary:
1234
Enter Your House Rent:
34444
Your name is okay
Your Total Salary is 35678.0
Deep Shikhar Singh (to Everyone): 09:30: Enter Your Employer Name:
deep
Enter Your Basic Salary:
90000
Enter Your House Rent:
10000
Your name is abc
Your Total Salary is 100000.0
Kushagra Gupta (to Everyone): 09:30: Enter Your Employer Name:
kush
Enter Your Basic Salary:
50000
Enter Your House Rent:
15000
Your name is abc
Your Total Salary is 65000.0
Vijeta Vinod Savant (to Everyone): 09:30: Enter Your Employer Name:Vijeta
Enter Your Basic Salary:15000
Enter Your House Rent:5000
Your name is VijetaYour Total Salary is 20000.0
Abhishek Rana (to Everyone): 09:30: Enter Your Employer Name:
abchj
Enter Your Basic Salary:
1000000
Enter Your House Rent:
22
Your name is abchj
Your Total Salary is 1000022.0

Saumya Vishwakarma (to Everyone): 09:30: Enter Your Employer Name:


Saumya
Enter Your Basic Salary:
50000
Enter Your House Rent:
10000
Your name is Saumya
Your Total Salary is 60000.0
K Prasanna Kumar (to Everyone): 09:31: Enter Your Employer Name:
ABCd
Enter Your Basic Salary:
1220
Enter Your House Rent:
12000
Your name is ABCd
Your Total Salary is 13220.0
MAYANK KUMAR (to Everyone): 09:31: Enter Your Employer Name:
mayank kumar
Enter Your Basic Salary:
20000
Enter Your House Rent:
5000
Your name is mayank kumar
Your Total Salary is 25000.0

Atul Gupta (to Everyone): 09:31: Enter Your Employer Name:


Abc
Enter Your Basic Salary:
10000
Enter Your House Rent:
2000
Your name is Abc
Your Total Salary is 12000.0
Shivaksh Ahalawat (to Everyone): 09:31: Enter Your Employer Name:
Shivaksh
Enter Your Basic Salary:
4000
Enter Your House Rent:
5000
Your name is Shivaksh
Your Total Salary is 9000.0

Abhishek Kaushik (to Everyone): 09:31: Enter Your Employer Name:


shivam
Enter Your Basic Salary:
120202
Enter Your House Rent:
22234
Your name is shivam
Your Total Salary is 142436.0

ananya giridhar (to Everyone): 09:32: Enter Your Employer Name:


Ananya G
Enter Your Basic Salary:
10000
Enter Your House Rent:
3000
Your name is Ananya G
Your Total Salary is 13000.0
Saloni Dhawan (to Everyone): 09:32: Enter Your Employer Name:
Saloni
Enter Your Basic Salary:
50000
Enter Your House Rent:
10000
Your name is Saloni
Your Total Salary is 60000.0
Piyush Shukla (to Everyone): 09:33: Enter Your Employer Name:
ABC
Enter Your Basic Salary:
2300
Enter Your House Rent:
1234
Your name is ABC
Your Total Salary is 3534.0

Monica (to Everyone): 09:33: import java.util.Scanner;  


class GetInputFromUser {
public static void main(String args[]) {
int a; float b; String s;  
Scanner in = new Scanner(System.in);  
System.out.println("Enter a string");
s = in.nextLine();
System.out.println("You entered string "+s);  
System.out.println("Enter an integer");
a = in.nextInt();
System.out.println("You entered integer "+a);  
System.out.println("Enter a float");
b = in.nextFloat();
System.out.println("You entered float "+b);
     }
}

Syed Ali Abbas (to Everyone): 09:34: Enter a string


ok
You entered string ok
Enter an integer
23
You entered integer 23
Enter a float
23.90
You entered float 23.9

Atul Gupta (to Everyone): 09:34: Enter a string


abc
You entered string abc
Enter an integer
10
You entered integer 10
Enter a float
20
You entered float 20.0
AMAN SAXENA (to Everyone): 09:35: Enter Your Employer Name:
jak
Enter Your Basic Salary:
565
Enter Your House Rent:
101
Your name is jak
Your Total Salary is 666.0

AMAN SAXENA (to Everyone): 09:35: Enter a string


aman
You entered string aman
Enter an integer
22
You entered integer 22
Enter a float
22.54
You entered float 22.54

Kushagra Gupta (to Everyone): 09:35: Enter a string


kush
You entered string kush
Enter an integer
15
You entered integer 15
Enter a float
18
You entered float 18.0

Saumya Vishwakarma (to Everyone): 09:36: Enter a string


asd
You entered string asd
Enter an integer
10
You entered integer 10
Enter a float
100
You entered float 100.0

ananya giridhar (to Everyone): 09:37: Enter a string


Ananya
You entered string Ananya
Enter an integer
23
You entered integer 23
Enter a float
45.7
You entered float 45.7

APURV AGNIHOTRI (to Everyone): 09:37: Enter a string


5555
You entered string 5555
Enter an integer
10
You entered integer 10
Enter a float
10.23
You entered float 10.23

Deep Shikhar Singh (to Everyone): 09:37: Enter a string


deep
You entered string deep
Enter an integer
10
You entered integer 10
Enter a float
100
You entered float 100.0
Akshay Singh (to Everyone): 09:38: Enter a string
abc
You entered string abc
Enter an integer
10
You entered integer 10
Enter a float
20
You entered float 20.0

Yashas Anand (to Everyone): 09:38: Enter a string


abc
You entered string abc
Enter an integer
10
You entered integer 10
Enter a float
20
You entered float 20.0
Shipra Yadav (to Everyone): 09:38: Enter a string
Shj
You entered string shj
Enter an integer
100
You entered integer 100
Enter a float
20
You entered float 20.0
Saloni Dhawan (to Everyone): 09:42: Enter a string
string
You entered string string
Enter an integer
56
You entered integer 56
Enter a float
79.08
You entered float 79.08
Monica (to Everyone): 09:51: package Batch1;

public class Test {


public static void main(String[] arg)
{
int i=1;
for(String s:arg) {
System.out.println((i++) +": "+ s );
}
System.out.println("Hello");

Abhishek Rana (to Everyone): 09:51: 1: Abc


2: def
Hello world

Harthik Ps (to Everyone): 09:51: 1: abc


2: def
Hello world

Kushagra Gupta (to Everyone): 09:51: 1: Abc


2: def
Hello world
Vijeta Vinod Savant (to Everyone): 09:51: 1: abc
2: def
Hello
AMAN SAXENA (to Everyone): 09:51: 1:aman
2:saxena
DONE

shivendra gupta (to Everyone): 09:52: 1: abc


2: def
Hello world
Ravi Pratap (to Everyone): 09:52: 1: abc
2: def
Hello
Naveen Kumar Mittal (to Everyone): 09:52: 1: abc
2: def
Hello

APURV AGNIHOTRI (to Everyone): 09:52: 1: abc


2: def
Hello
Abhishek Kaushik (to Everyone): 09:52: 1: abc
2: def
Hello

Saumya Vishwakarma (to Everyone): 09:52: 1: Saumya


2: Vishwakarma
Hello world
Shipra Yadav (to Everyone): 09:52: 1: abc
2: def
Hello
Piyush Shukla (to Everyone): 09:52: 1: abc
2: def
Hello world
Syed Ali Abbas (to Everyone): 09:53: 1: abc
2: def
Hello world

K Prasanna Kumar (to Everyone): 09:53: 1: Good


2: Morning
Hello

Akshay Singh (to Everyone): 09:53: 1: 12


2: 23
Hello
MAYANK KUMAR (to Everyone): 09:53: 1: may
2: ank
Hello
Sumukh G (to Everyone): 09:53: 1: Good
2: Morning
Hello
Yashas Anand (to Everyone): 09:54: 1: abc
2: def
Hello

Shivaksh Ahalawat (to Everyone): 09:56: please anyone send the code again I leave for
a second and chat was cleared
AMAN SAXENA (to Everyone): 09:56: package Batch1;

public class Test {


public static void main(String[] arg)
{
    int i=1;
    for(String s:arg) {
      System.out.println((i++) +": "+ s );
  }
    System.out.println("Hello");
  
}

}
Shivaksh Ahalawat (to Everyone): 09:56: Thank you
AMAN SAXENA (to Everyone): 09:56: Welcome
AMAN SAXENA (to Everyone): 09:58: Saloni by mistake you have sent me
Shivaksh Ahalawat (to Everyone): 09:59: 1: Hello
2: World
Hello

Monica (to Everyone): 10:09: package Batch1;

import java.io.FileOutputStream;

public class FileOutputStreamExample {


public static void main(String args[]) {
try {
FileOutputStream fout = new FileOutputStream("C:\\Monica\\
test.txt");
String s = "Hello World!";
byte b[] = s.getBytes();// converting string into byte array
fout.write(b);
fout.close();
System.out.println("File OverWritten/Created");
} catch (Exception e) {
System.out.println(e);
}
}
}

Monica (to Everyone): 10:15: import java.io.FileOutputStream;

public class FileOutputStreamExample {


public static void main(String args[]) {
try {
FileOutputStream fout = new FileOutputStream(".\\src\\
FileOutputStreamExample1.java");
String s = "//Hello World!";
byte b[] = s.getBytes();// converting string into byte array
fout.write(b);
fout.close();
System.out.println("File OverWritten/Created");
} catch (Exception e) {
System.out.println(e);
}
}
}

Akshay Singh (to Everyone): 10:16: //Hello World!


Monica (to Everyone): 10:16: Hello World!
Harthik Ps (to Everyone): 10:16: //Hello World!

Monica (to Everyone): 10:17: //Hello World!


AMAN SAXENA (to Everyone): 10:17: Absolute Referencing......Hello World!
K Prasanna Kumar (to Everyone): 10:17: //Hello World!
Syed Ali Abbas (to Everyone): 10:17: could you explain once again how to run them?
Abhishek Rana (to Everyone): 10:17: //Hello World!

Shipra Yadav (to Everyone): 10:17: //Hello World!


Harthik Ps (to Everyone): 10:17: Hello World!

Kushagra Gupta (to Everyone): 10:17: Hello World!


Vijeta Vinod Savant (to Everyone): 10:17: Hello World!
K Prasanna Kumar (to Everyone): 10:17: Hello World!
APURV AGNIHOTRI (to Everyone): 10:17: Hello World!

Saumya Vishwakarma (to Everyone): 10:17: //Hello World!


Shipra Yadav (to Everyone): 10:17: Hello World!
Sumukh G (to Everyone): 10:18: //Helloworld!!
Piyush Shukla (to Everyone): 10:18: //Hello Everyone
Saumya Vishwakarma (to Everyone): 10:18: Hello World!
Challa Bhavya (to Everyone): 10:18: //Helloworld!!

Saloni Dhawan (to Everyone): 10:18: Hello World

Sumukh G (to Everyone): 10:18: Hello World


AMAN SAXENA (to Everyone): 10:18: //Hello World!

Deep Shikhar Singh (to Everyone): 10:18: Hello World!

shivendra gupta (to Everyone): 10:18: //Hello World!

Ravi Pratap (to Everyone): 10:19: //Hello World!


Deep Shikhar Singh (to Everyone): 10:19: //Hello World!
MAYANK KUMAR (to Everyone): 10:19: Hello World!
Atul Gupta (to Everyone): 10:19: Hello World!
Abhishek Kaushik (to Everyone): 10:19: //Hello World!
Shikhar Shukla (to Everyone): 10:20: Ma'am why it does'nt work without exception
handling/ try-catch block?
Shivaksh Ahalawat (to Everyone): 10:20: Hello World!
Vijeta Vinod Savant (to Everyone): 10:21: //Hello World!
Atul Gupta (to Everyone): 10:22: //Hello World!
Shivaksh Ahalawat (to Everyone): 10:22: //Hello World!
Shikhar Shukla (to Everyone): 10:22: Hello World!
Abhishek Kaushik (to Everyone): 10:23: Hello World!

Monica (to Everyone): 10:24: import java.io.FileInputStream;   


public class FileInputStreamExample {   
          public static void main(String args[]){       
                    try{       
                        FileInputStream fin=new FileInputStream("C:\\Monica\\test.txt");       
                        int i=0;       
                        while((i=fin.read())!=-1){       
                          System.out.print((char)i);       
                        }       
                        fin.close();       
                    }catch(Exception e){System.out.println(e);}       
                  }       
        }
//Hello World!

Shivaksh Ahalawat (to Everyone): 10:27: Hello World!


Piyush Shukla (to Everyone): 10:27: Hello World!
Ravi Pratap (to Everyone): 10:27: Hello World!
K Prasanna Kumar (to Everyone): 10:27: Hello World!
Akshay Singh (to Everyone): 10:27: Hello World!

AMAN SAXENA (to Everyone): 10:28: Hello World!


Saumya Vishwakarma (to Everyone): 10:28: Hello World!

Vijeta Vinod Savant (to Everyone): 10:28: Hello World!


APURV AGNIHOTRI (to Everyone): 10:28: Hello World!
Deep Shikhar Singh (to Everyone): 10:28: Hello World!
Abhishek Kaushik (to Everyone): 10:28: Hello World!
shivendra gupta (to Everyone): 10:28: Hello World!
Shipra Yadav (to Everyone): 10:28: Hello World!
Monica (to Everyone): 10:29: Add a menu driven program to have
1. Enter a file name with path
2. Write to the above file (scan the input string)
3. Read from the above file
4. Exit
Use Proper exception handling

Monica (to Everyone): 10:29: tea break 15 min


AMAN SAXENA (to Everyone): 10:30: yes ma'am
Saloni Dhawan (to Everyone): 10:30: yes mam
Saumya Vishwakarma (to Everyone): 10:30: Yes mam
Abhishek Kaushik (to Everyone): 10:30: yes maam
Kushagra Gupta (to Everyone): 10:30: yes
Shivaksh Ahalawat (to Everyone): 10:30: yes
Kushagra Gupta (to Everyone): 10:45: back
Abhishek Kaushik (to Everyone): 10:45: back
shivendra gupta (to Everyone): 10:45: back
Piyush Shukla (to Everyone): 10:45: Back
Saumya Vishwakarma (to Everyone): 10:45: Back
K Prasanna Kumar (to Everyone): 10:45: back
AMAN SAXENA (to Everyone): 10:46: back
Shivaksh Ahalawat (to Everyone): 10:46: back
Harshit Mimani (to Everyone): 10:46: back

Deep Shikhar Singh (to Everyone): 10:46: back


Naveen Kumar Mittal (to Everyone): 10:46: back
Ravi Pratap (to Everyone): 10:46: back
Chirag Yadav (to Everyone): 10:46: back
ananya giridhar (to Everyone): 10:46: back
Shikhar Shukla (to Everyone): 10:46: back
Challa Bhavya (to Everyone): 10:46: back
Atul Gupta (to Everyone): 10:48: back
Akshay Singh (to Everyone): 10:49: Back
Monica (to Everyone): 11:39: import java.io.File;
public class FileDemo {
      public static void main(String[] args) {
            File f = null;
            String s = "C:\\Monica\\test.txt";
            try {
                          // create new file
                        f = new File(s);
                        // true if the file is executable
                        boolean bool = f.canExecute();
                        // find the absolute path
                        String a = f.getAbsolutePath();
                        // prints absolute path
                        System.out.print(a);
                        System.out.println(" is executable: "+ bool);
            } catch (Exception e) {
                  // if any I/O error occurs
                  e.printStackTrace();
      }
   }
}

Piyush Shukla (to Everyone): 11:41: C:\Piyush\test.txt is executable: true

Atul Gupta (to Everyone): 11:41: C:\Monica\test.txt is executable: false

MAYANK KUMAR (to Everyone): 11:41: C:\mayank\test.txt is executable: true


AMAN SAXENA (to Everyone): 11:41: C:\Monica\test.txt is executable: false

Shikhar Shukla (to Everyone): 11:41: C:\Monica\test.txt is executable: false


Saumya Vishwakarma (to Everyone): 11:41: C:\Monica\test.txt is executable: false

Harthik Ps (to Everyone): 11:42: D:\APPS\java\Harthik\test.txt is executable: true

Vijeta Vinod Savant (to Everyone): 11:42: C:\Users\USER\Desktop\Ex.txt is executable:


true
Kushagra Gupta (to Everyone): 11:42: C:\kush\test.txt is executable: true

Challa Bhavya (to Everyone): 11:42: C:\Monica\test.txt is executable: true

Shivaksh Ahalawat (to Everyone): 11:42: S:\ShivakshIO\test.txt is executable: true


AMAN SAXENA (to Everyone): 11:42: E:\aman_java\test.txt is executable: true
Saloni Dhawan (to Everyone): 11:42: C:\Monica\test.txt is executable: false\
shivendra gupta (to Everyone): 11:42: C:\Monica\test.txt is executable: false
Saloni Dhawan (to Everyone): 11:42: C:\Monica\test.txt is executable: false
Naveen Kumar Mittal (to Everyone): 11:43: C:\naveen\test.txt is executable: true

APURV AGNIHOTRI (to Everyone): 11:43: G:\Java\test.txt is executable: true

Akshay Singh (to Everyone): 11:43: C:\Monica\test.txt is executable: false


Monica (to Everyone): 11:44: import java.io.*;
import java.util.*;
public class ScannerExample {
public static void main(String args[]) throws FileNotFoundException {
// creating File instance to reference text file in Java
File text = new File("C://Monica//test.txt");
// Creating Scanner instnace to read File in Java
Scanner scnr = new Scanner(text);
// Reading each line of file using Scanner class
int lineNumber = 1;
while (scnr.hasNextLine()) {
String line = scnr.nextLine();
System.out.println("line " + (lineNumber++) + " :" + line);
}
}
}

Syed Ali Abbas (to Everyone): 11:45: C:\Users\aliab\onedrive\desktop\test.txt is


executable: true

Syed Ali Abbas (to Everyone): 11:46: line 1 :hello


Shivaksh Ahalawat (to Everyone): 11:46: line 1 :Hello World!
line 2 :My name is Shivaksh Ahalawat

Piyush Shukla (to Everyone): 11:46: line 1 :Hello World!


line 2 :Java is a Great Programming language
line 3 :IO is in util

Harthik Ps (to Everyone): 11:46: line 1 :Hello World!


line 2 :reading text file succesfull

Akshay Singh (to Everyone): 11:46: line 1 :Hello World!323


Saumya Vishwakarma (to Everyone): 11:46: line 1 :Hello
line 2 :Everyone
line 3 :Im Saumya

Naveen Kumar Mittal (to Everyone): 11:46: line 1 :naveen


line 2 :hello world
line 3 :java is great

MAYANK KUMAR (to Everyone): 11:46: line 1 :hello mayank


line 2 :this is java
Shipra Yadav (to Everyone): 11:47: line 1 :Hello
line 2 :Java is a Great
l

Vijeta Vinod Savant (to Everyone): 11:47: line 1 :Hello World.


line 2 :Java is great.
Shikhar Shukla (to Everyone): 11:47: line 1 :Hello World.
line 2 :Java is great.

AMAN SAXENA (to Everyone): 11:47: line 1 :aman saxena


line 2 :hello
line 3 :everyone

Atul Gupta (to Everyone): 11:48: line 1 ://Hello World!


line 2 :what is your name
line 3 :my name is atul

K Prasanna Kumar (to Everyone): 11:48: line 1 :Hello World.


line 2 :Java is great.
Harshit Mimani (to Everyone): 11:48: line 1 ://Hello World!
line 2 :Welcome
Ravi Pratap (to Everyone): 11:48: line 1 :abcdef
line 2 :ghi
APURV AGNIHOTRI (to Everyone): 11:49: line 1 :hi
line 2 :hello
line 3 :thanks
Monica (to Everyone): 11:49: import java.io.*;
public class FileReadWrite {
      public static void main(String args[])throws IOException {
            File file = new File("/Monica/Hello.txt");
            // creates the file
            file.createNewFile();
            // creates a FileWriter Object
            FileWriter writer = new FileWriter(file);
            // Writes the content to the file
            writer.write("This\n is
an
example of\n File Reader and Writer");
            writer.flush();
            writer.close();
            // Creates a FileReader Object
            FileReader fr = new FileReader(file);
            char [] a = new char[50];
            fr.read(a);      // reads the content to the array
            for(char c : a)
                  System.out.print(c);      // prints the characters one by one
            fr.close();
   }
}

Deep Shikhar Singh (to Everyone): 11:50: line 1 ://Hello World!


line 2 :Welcome

Piyush Shukla (to Everyone): 11:51: This


is
an
example of
File Reader and Writer
Atul Gupta (to Everyone): 11:51: This
is example of
File Reader and Writer
Harthik Ps (to Everyone): 11:51: This
is
an
example of
File Reader and Writer
Shikhar Shukla (to Everyone): 11:52: Yes ma'am
Piyush Shukla (to Everyone): 11:52: Yes Ma'am
Kushagra Gupta (to Everyone): 11:52: sure maam
Shipra Yadav (to Everyone): 11:52: This
is
an
example of
File Reader and Writer
Kushagra Gupta (to Everyone): 11:52: no problem
AMAN SAXENA (to Everyone): 11:52: Sure ma'am
Deep Shikhar Singh (to Everyone): 11:52: yes maam
Harthik Ps (to Everyone): 11:52: yes mam
Vijeta Vinod Savant (to Everyone): 11:52: Yes Ma'am

Saumya Vishwakarma (to Everyone): 11:52: Ok Ma'am


shivendra gupta (to Everyone): 11:52: yes mam
Shipra Yadav (to Everyone): 11:52: Yes mam
Naveen Kumar Mittal (to Everyone): 11:52: yes ma'am
Harshit Mimani (to Everyone): 11:52: Yes Ma'am
MAYANK KUMAR (to Everyone): 11:52: This
is an example of
File Reader and Writer
Kushagra Gupta (to Everyone): 11:52: This
is an example of
File Reader and Writer

Naveen Kumar Mittal (to Everyone): 11:53: This


is an example of
File Reader and Writer
K Prasanna Kumar (to Everyone): 11:53: This
is an example of
File Reader and Writer
Ravi Pratap (to Everyone): 11:53: This
is an example of
File Reader and Writer

Shivaksh Ahalawat (to Everyone): 11:53: This


is an example of
File Reader and Writer
Deep Shikhar Singh (to Everyone): 11:53: This
is an example of
File Reader and Writer

AMAN SAXENA (to Everyone): 11:53: This


is an example of
File Reader and Writer

Abhishek Kaushik (to Everyone): 11:53: This


is an example of
File Reader and Writer
Vijeta Vinod Savant (to Everyone): 11:54: This
is an example of
File Reader and Writer
Saumya Vishwakarma (to Everyone): 11:54: This
is an example of
File Reader and Writer
Piyush Shukla (to Everyone): 11:54: Yes Ma'am
AMAN SAXENA (to Everyone): 11:54: Yes ma'am
Akshay Singh (to Everyone): 11:55: This
is an example of
File Reader and Writer

Monica (to Everyone): 12:05: import java.io.*;

public class FileCopy {


public static void main(String[] args) {
//C:\\Monica\\Hello.txt C:\\MonicaHelloCopy.txt
if (args.length != 2)
System.err.println("Usage: java FileCopy <source file>
<destination>");
else {
try {
copy(args[0], args[1]);
} catch (Exception e) {
System.err.println(e.getMessage());
}
}
}

public static void copy(String from_name, String to_name) throws IOException {


File from_file = new File(from_name);
File to_file = new File(to_name);
FileInputStream from = null;
FileOutputStream to = null;
try {
from = new FileInputStream(from_file);
to = new FileOutputStream(to_file);
byte[] buffer = new byte[4096];
int bytes_read;
while ((bytes_read = from.read(buffer)) != -1)
to.write(buffer, 0, bytes_read);
} finally {
if (from != null || to != null)
try {
from.close();
to.close();
} catch (IOException e) {

}
}
}
}

Kushagra Gupta (to Everyone): 12:09: Usage: java FileCopy <source file>
<destination>
Piyush Shukla (to Everyone): 12:11: Usage: java FileCopy <source file> <destination>

Shipra Yadav (to Everyone): 12:11: Usage: java FileCopy <source file>
<destination>
AMAN SAXENA (to Everyone): 12:11: Usage: java FileCopy <source file>
<destination>

Deep Shikhar Singh (to Everyone): 12:11: Usage: java FileCopy <source file>
<destination>
shivendra gupta (to Everyone): 12:11: Usage: java FileCopy <source file>
<destination>
Saumya Vishwakarma (to Everyone): 12:11: Usage: java FileCopy <source file>
<destination>

Atul Gupta (to Everyone): 12:11: Usage: java FileCopy <source file> <destination>

APURV AGNIHOTRI (to Everyone): 12:11: Usage: java FileCopy <source file>
<destination>
Vijeta Vinod Savant (to Everyone): 12:11: Usage: java FileCopy <source file>
<destination>
Chirag Yadav (to Everyone): 12:11: Usage: java FileCopy <source file> <destination>

Akshay Singh (to Everyone): 12:12: it is created    new file


Mohit Rai (to Everyone): 12:12: Usage: java FileCopy <source file> <destination>
Ravi Pratap (to Everyone): 12:12: Usage: java FileCopy <source file> <destination>

Harthik Ps (to Everyone): 12:12: copying Successfull

Shipra Yadav (to Everyone): 12:14: Yes mam


Monica (to Everyone): 12:20: Run the previous program by copying a .java file and
pasting it to same named .clas file
Only one arg will be passed with ext .java
Save the entire content of the file in another file with the same name and ext .clas
>java FileCopy aa.java
Output: aa.clas
Content of aa.clas is the same as aa.java

Monica (to Everyone): 12:42: import java.io.*;

public class FileCopy {


public static void main(String[] args) {
//C:\\Monica\\abc.java
if (args.length != 1)
System.err.println("Usage: java FileCopy <source file>");
else if(!args[0].endsWith(".java"))
System.err.println("Usage: <source file> is not a .java file");
else {
try {
String a=args[0].replaceAll(".java",".clas");
copy(args[0], a);
} catch (Exception e) {
System.err.println(e.getMessage());
}
}
}

public static void copy(String from_name, String to_name) throws IOException {


File from_file = new File(from_name);
File to_file = new File(to_name);
FileInputStream from = null;
FileOutputStream to = null;
try {
from = new FileInputStream(from_file);
to = new FileOutputStream(to_file);
byte[] buffer = new byte[4096];
int bytes_read;
while ((bytes_read = from.read(buffer)) != -1)
to.write(buffer, 0, bytes_read);
} finally {
if (from != null || to != null)
System.out.println("Compiled Successfully");
try {
from.close();
to.close();
} catch (IOException e) {

}
}
}
}

Monica (to Everyone): 12:47: Write a Java program to prompt a user to input his/her
name and then the output be shown as an example below:
Hello <Name>!
Append the Content + Login time(System time when the Name was entered) to a file:
Name_Collection.txt
Hint:Second parameter in FileWriter is to be true to append.
FileWriter fileWritter = new FileWriter(data,true);

Eg:
Run1: Enter Name: Monica    Output: Hello Monica!
Run2: Enter Name: Ishu    Output: Hello Ishu!
Name_Collection.txt
Monica    Login time: 11:47 AM 25-08-2018
Ishu    Login time: 11:49 AM 25-08-2018
Monica (to Everyone): 13:00: Topic: Java Packages through cmd line
Presenter: Atul Gupta

Naveen Kumar Mittal (to Everyone): 13:04: thank you ma'am


Deep Shikhar Singh (to Everyone): 13:04: thank you ma'am
Saumya Vishwakarma (to Everyone): 13:04: Thanku ma'am
Piyush Shukla (to Everyone): 13:04: Thank you Ma'am
shivendra gupta (to Everyone): 13:04: thankyou mam.
K Prasanna Kumar (to Everyone): 13:04: Thank you maam
Chirag Yadav (to Everyone): 13:04: thank you
AMAN SAXENA (to Everyone): 13:04: thank you ma'am
Shikhar Shukla (to Everyone): 13:04: Thankyou ma'am

You might also like