Selenium Class 13 - Java IO Operations

preview_player
Показать описание
Automated Testing using Selenium and Java Programming, Java Programming Fundamentals for Software Testers, Java Input and Output Operations, Read data using Input devices like Mouse and Keyboard, Read Data from Files, and Read Data from Application Objects.
File Handling in Java, Create & Delete Computer Files, Read Files, and Write data to Files. Predefined Objects usage in Java Programming, Java File Class, FileReader Class, BufferedReader, FileWriter, and BufferedWriter. Generate IO Exceptions in Java Programming.
Рекомендации по теме
Комментарии
Автор

Selenium Class 13: Java IO Operations

i) Java IO Operations
ii) File Handling in Java

i) Java IO Operations

Input and Output Operations

Input:
Input using Input devices (Keyboard & Mouse)
Read Data from Files (Text/Excel/Database Files....)
*Read Data from the Application (AUT) Objects/Elements
Output:
Display message/s on Computer Console/Eclipse IDE Console
Display Variable Values
Display Variable values and Messages
Write data to a file

There are three ways to read input in Java,

1) Scanner
2) DataInputStream
3) BufferedReader

> Using java.util.Scanner is the easier way and it includes many methods
to check the Input is valid or not?

Example for Reading input using Input devices:

public static void main(String[] args) {
Scanner scan = new Scanner(System.in);

System.out.println("Enter Your Name: ");
String name=scan.nextLine();
System.out.println("Your Name is: "+ name);

System.out.println("Enter Your City:");
String city=scan.next();
System.out.println("Your City is: "+ city);

System.out.println("Enter Your Mobile Number: ");
long mobile =scan.nextLong();
System.out.println("Your Mobile Number is: "+ mobile);

System.out.println("Enter Your Id: ");
int id=scan.nextInt();
System.out.println("Your Id is: "+id);

System.out.println("Enter a Value:");
boolean val=scan.nextBoolean();
System.out.println("Your Value is: "+val);

System.out.println("Enter a Number with decimal places:");
double d=scan.nextDouble();
System.out.println("Your Number is: "+d);

System.out.println("Enter a Character: ");
char a= scan.next().charAt(0);
System.out.println("Your Character is: "+a);

Display output on the console

int a=10, b=20;

System.out.println(a);//10
System.out.println(a*b);//200
System.out.println("Selenium Testing");//Selenium Testing
System.out.println("Addition of a, b is: "+ (a+b));
System.out.println("");
System.out.println("a Value is: "+a+" b value is: "+b);

ii) File Handling in Java

> User Point of view file means Text / Flat File or Excel File or Word document or PDF etc....

> Computer Point of view File Means - Driver, Folder, File, Database....

IO Operations in VBScript:

Input and Output Operations - using InputBox and MsgBOx Functions

File Handling:
i) File System Object - to handle Drives, Folders, and Files(Text/Flat....)
ii) Excel Application Object - to handle Excel Files
iii) Word Application Object - to handle Word documents
iv) Database Object - To handle Database Operations
(Database Connection, Database Recordset, Database Command)

In Java:

Input and Output Operations - Scanner (predefined), System (built-in) Classes....

File handling:

File Class - Driver, Folder, File (Text Files only)
Reading and Writing Operations (BufferedReader, and BufferedWriter)
Excel files - import External Excel jar and add to Java your Project in Eclipse IDE
Note: for other type of files also import those jars....

Java Features usage:
i) Built-in - Use directly (Ex: System Class)
ii) Predefined - import the Library and Use (Scanner, File...)
iii) External - Download the jar, add to your Java project, import and use (excel.jar)

Examples:

1) Create a Folder on Desktop

File fileObject = new
fileObject.mkdir();

2) Delete a Folder
File file=new
boolean fileExists=file.exists();
if (fileExists == true){
System.out.println("Selenium Folder is Exists -Passed");
}
else {
System.out.println("Selenium Folder is Not Exists -Failed");
}

file.delete();

fileExists=file.exists();
if (fileExists == true){
System.out.println("Selenium Folder is Exists -Passed");
}
else {
System.out.println("Selenium Folder is Not Exists -Failed");
}

Note: Using File Class/Object we can handle Flat Files only, we can create and delete other type of
Files also but we cannot conduct internal operations.

3) Create a Text File

public static void main (String [] args) throws IOException{
File abc = new
abc.createNewFile();

4) Read a Text File

String line;
//Open a File in Read Mode
FileReader abc = new
// Read the Data from an Opened File
BufferedReader br = new BufferedReader(abc);

while ((line=br.readLine()) !=null){
System.out.println(line);
}
br.close();
abc.close();

5) Write data to a Text File
//Open a File in Write Mode
FileWriter file= new
//Write data to a Text File
BufferedWriter bw=new BufferedWriter(file);

String data = "Welcome to Selenium";
bw.write(data);
bw.close();
file.close();

6) Read a Text File & Write to another File

String line;
FileReader file1=new
FileWriter file2=new FileWriter

BufferedReader br= new BufferedReader(file1);
BufferedWriter bw= new BufferedWriter (file2);

while ((line=br.readLine()) !=null){
bw.write(line);
bw.newLine();
}
bw.close();
br.close();
file2.close();
file1.close();

nidhidubey
Автор

Thank you so much Sir, its really very informative, But can not find the notes in the comment.

nidhidubey
Автор

Class Notes:
Selenium Class 13: Java IO Operations

i) Java IO Operations
ii) File Handling in Java

i) Java IO Operations

Input and Output Operations

Input:
Input using Input devices (Keyboard & Mouse)
Read Data from Files (Text/Excel/Database Files....)
*Read Data from the Application (AUT) Objects/Elements
Output:
Display message/s on Computer Console/Eclipse IDE Console
Display Variable Values
Display Variable values and Messages
Write data to a file

There are three ways to read input in Java,

1) Scanner
2) DataInputStream
3) BufferedReader

> Using java.util.Scanner is the easier way and it includes many methods
to check the Input is valid or not?

Example for Reading input using Input devices:

public static void main(String[] args) {
Scanner scan = new Scanner(System.in);

System.out.println("Enter Your Name: ");
String name=scan.nextLine();
System.out.println("Your Name is: "+ name);

System.out.println("Enter Your City:");
String city=scan.next();
System.out.println("Your City is: "+ city);

System.out.println("Enter Your Mobile Number: ");
long mobile =scan.nextLong();
System.out.println("Your Mobile Number is: "+ mobile);

System.out.println("Enter Your Id: ");
int id=scan.nextInt();
System.out.println("Your Id is: "+id);

System.out.println("Enter a Value:");
boolean val=scan.nextBoolean();
System.out.println("Your Value is: "+val);

System.out.println("Enter a Number with decimal places:");
double d=scan.nextDouble();
System.out.println("Your Number is: "+d);

System.out.println("Enter a Character: ");
char a= scan.next().charAt(0);
System.out.println("Your Character is: "+a);

Display output on the console

int a=10, b=20;

System.out.println(a);//10
System.out.println(a*b);//200
System.out.println("Selenium Testing");//Selenium Testing
System.out.println("Addition of a, b is: "+ (a+b));
System.out.println("");
System.out.println("a Value is: "+a+" b value is: "+b);

ii) File Handling in Java

> User Point of view file means Text / Flat File or Excel File or Word document or PDF etc....

> Computer Point of view File Means - Driver, Folder, File, Database....

IO Operations in VBScript:

Input and Output Operations - using InputBox and MsgBOx Functions

File Handling:
i) File System Object - to handle Drives, Folders, and Files(Text/Flat....)
ii) Excel Application Object - to handle Excel Files
iii) Word Application Object - to handle Word documents
iv) Database Object - To handle Database Operations
(Database Connection, Database Recordset, Database Command)

In Java:

Input and Output Operations - Scanner (predefined), System (built-in) Classes....

File handling:

File Class - Driver, Folder, File (Text Files only)
Reading and Writing Operations (BufferedReader, and BufferedWriter)
Excel files - import External Excel jar and add to Java your Project in Eclipse IDE
Note: for other type of files also import those jars....

Java Features usage:
i) Built-in - Use directly (Ex: System Class)
ii) Predefined - import the Library and Use (Scanner, File...)
iii) External - Download the jar, add to your Java project, import and use (excel.jar)

Examples:

1) Create a Folder on Desktop

File fileObject = new
fileObject.mkdir();

2) Delete a Folder
File file=new
boolean fileExists=file.exists();
if (fileExists == true){
System.out.println("Selenium Folder is Exists -Passed");
}
else {
System.out.println("Selenium Folder is Not Exists -Failed");
}

file.delete();

fileExists=file.exists();
if (fileExists == true){
System.out.println("Selenium Folder is Exists -Passed");
}
else {
System.out.println("Selenium Folder is Not Exists -Failed");
}

Note: Using File Class/Object we can handle Flat Files only, we can create and delete other type of
Files also but we cannot conduct internal operations.

3) Create a Text File

public static void main (String [] args) throws IOException{
File abc = new
abc.createNewFile();

4) Read a Text File

String line;
//Open a File in Read Mode
FileReader abc = new
// Read the Data from an Opened File
BufferedReader br = new BufferedReader(abc);

while ((line=br.readLine()) !=null){
System.out.println(line);
}
br.close();
abc.close();

5) Write data to a Text File
//Open a File in Write Mode
FileWriter file= new
//Write data to a Text File
BufferedWriter bw=new BufferedWriter(file);

String data = "Welcome to Selenium";
bw.write(data);
bw.close();
file.close();

6) Read a Text File & Write to another File

String line;
FileReader file1=new
FileWriter file2=new FileWriter

BufferedReader br= new BufferedReader(file1);
BufferedWriter bw= new BufferedWriter (file2);

while ((line=br.readLine()) !=null){
bw.write(line);
bw.newLine();
}
bw.close();
br.close();
file2.close();
file1.close();

gcreddy
Автор

I could not find your notes.i wish you posted here this lessons notes

zinashtoibaeva
Автор

Sir, can you provide the note for this class?!

fuadkhan
Автор

Thank u sir, can you upload next class video

gopalreddy
Автор

added the notes that, Respected Reddy Sir has sent.

nidhidubey