Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- import java.io.*;
- import java.text.*;
- public class Lab9 {
- private final String FILEDIRECTORY = "C:\\Users\\Owner\\Desktop";
- private final String INPUTFILEPATH = "Lab9Input.txt";
- private final String OUTPUTFILEPATH = "Lab9Output.txt";
- public static void main(String[] args){
- Lab9 myClass = new Lab9();
- myClass.doIt();
- }
- public void doIt(){
- int recordCounter = 1;
- double payAmount = 0;
- DecimalFormat formatPay = new DecimalFormat("#####.##");
- String employeeName = null;
- String lineIn = null;
- String[] piecesOfDocument = new String[2];
- String myInputFile = FILEDIRECTORY + File.separator + INPUTFILEPATH;
- String myOutputFile = FILEDIRECTORY + File.separator + OUTPUTFILEPATH;
- try{
- File inputFile = new File(myInputFile);
- FileReader fr = new FileReader(inputFile);
- BufferedReader br = new BufferedReader(fr);
- File outputFile = new File(myOutputFile);
- FileWriter fw = new FileWriter(outputFile);
- BufferedWriter bw = new BufferedWriter(fw);
- while ((lineIn = br.readLine()) != null){
- piecesOfDocument = lineIn.split(":");
- employeeName = piecesOfDocument[0];
- payAmount = Double.parseDouble(piecesOfDocument[1]);
- bw.write(String.format("%4d %-20s %s %n", recordCounter, employeeName, formatPay.format(payAmount)));
- recordCounter++;
- }
- br.close();
- fr.close();
- bw.close();
- fw.close();
- }
- catch (Exception ex){
- MyError("File could not be read or written!", ex);
- }
- }
- public void MyError(String errMsg, Exception ex){
- System.out.println(errMsg);
- ex.printStackTrace();
- System.exit(1);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement