Ask a question to Desklib · AI bot


Create Files Based on State in Java Programming

Added on -2019-09-16

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.
| 3 pages
| 561 words

Trusted by 2+ million users,
1000+ happy students everyday

// Micheal Seals // IT 2650, Java Programing 85072// Due Date: November 17 2016 // Asssignment 7 import java.nio.file.*; import*; 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(; 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";

Found this document preview useful?

You are reading a preview
Upload your documents to download
Become a Desklib member to get accesss

Students who viewed this