This Java program creates two files based on the state of the customer, InStateCusts.txt and OutOfStateCusts.txt. It takes customer account number, name, state, and balance as input and writes them to the respective files. The program uses FileChannel and ByteBuffer classes to write data to the files. It also uses DecimalFormat class to format the balance value. The program creates empty files with 1000 records each using the createEmptyFile() method. The program handles exceptions using try-catch blocks.
Create Files Based on State in Java Programming
Added on 2019-09-16
BookmarkShareRelated Documents
// Micheal Seals // IT 2650, Java Programing 85072// Due Date: November 17 2016 // Asssignment 7 import java.nio.file.*; import java.io.*; import java.nio.channels.FileChannel; import java.nio.ByteBuffer; import static java.nio.file.StandardOpenOption.*; import java.util.Scanner; import java.text.*; public class CreateFilesBasedOnState{ public static void main(String[] args) { Scanner input= new Scanner(System.in); Path inStateFile=Paths.get("InStateCusts.txt"); Path outOfStateFile= Paths.get("OutOfStateCusts.txt"); final String ID_FORMAT= "000"; final String NAME_FORMAT= " "; final int NAME_LENGTH= NAME_FORMAT.length(); final String HOME_STATE= "WI"; final String BALANCE_FORMAT= "0000.00"; String delimiter= ","; String s= ID_FORMAT + delimiter + NAME_FORMAT + delimiter + HOME_STATE + delimiter + BALANCE_FORMAT + System.getProperty("line.separator"); final int RECSIZE=s.length(); FileChannel fcIn= null; FileChannel fcOut= null; String idString; int id; String name; String state; double balance; final String QUIT="999";
End of preview
Want to access all the pages? Upload your documents or become a member.
Related Documents
R programming for analyzing flight dataset and flight schedulinglg...
|26
|1439
|140
Java Programming Assignments with Solutionslg...
|9
|904
|164
Design Documentation Pseudo Code BEGIN Display Welcome message BEGINlg...