Using any application of your choice, write two Java programs that meet the following requirements:

First program:
Name of the program must be WritingToIO;
The program uses two variables named emplNum and salary;
The program must be able to accept values for each of the variables and save the information to a file called SalariesData.txt.

Second program:
Name of the program must be ReadingFromIO;
This program must ensure the information/ values can be retrieved from the file SalariesData.txt referred to in Step 1a above (i.e. the file where the employee salary data was written to).

First program (WritingToIO):

import java.io.FileWriter;
import java.io.IOException;

public class WritingToIO {
public static void main(String[] args) {
int emplNum = 12345;
double salary = 5000.00;

try {
FileWriter writer = new FileWriter("SalariesData.txt");
writer.write("Employee Number: " + emplNum + "\n");
writer.write("Salary: $" + salary + "\n");
writer.close();
System.out.println("Data written successfully to SalariesData.txt");
} catch (IOException e) {
System.out.println("An error occurred while writing to the file.");
e.printStackTrace();
}
}
}

This program uses the FileWriter class to write the employee number and salary to the file "SalariesData.txt". It uses the variables emplNum and salary to store the values. The file is closed after writing the data, and a success message is displayed if the operation is successful.

Second program (ReadingFromIO):

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;

public class ReadingFromIO {
public static void main(String[] args) {
try {
FileReader reader = new FileReader("SalariesData.txt");
BufferedReader bufferedReader = new BufferedReader(reader);

String line;
while ((line = bufferedReader.readLine()) != null) {
System.out.println(line);
}
reader.close();
} catch (IOException e) {
System.out.println("An error occurred while reading the file.");
e.printStackTrace();
}
}
}

This program uses the FileReader class along with BufferedReader to read the contents of the file "SalariesData.txt". It reads each line of the file and prints it on the console. If an error occurs while reading the file, an error message is displayed along with the stack trace.