import java.nio.file."; import java.io.*; import java.nio.channels.FileChannel; import java.nio.ByteBuffer; import stati
Posted: Sun May 15, 2022 11:38 am
it is not letting me insert copiable code
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; public class CreateEmployeesRandomFile { public static void main(String[] args) { Scanner input = new Scanner(System.in); Path file = Paths.get("C:\\Users\\antho\\Documents\\316 - Programming|\Random Employees.txt"); String s - "000, ,00.00" . System.getProperty("line.separator"); final int RECSIZE = s.length(); FileChannel fc = null; String delimiter - ","; String idString; int id; String name; I String payRate; final String QUIT = "999"; try fc = (FileChannel)Files.newByteChannel(file, READ, WRITE); System.out.print("Enter employee ID number >> "); idString - input.nextLine(); while(!(idString.equals(QUIT))) { id - Integer.parseInt(idString), System.out.print("Enter name for employee " . id »>"); input.nextLine(); System.out.print("Enter pay rate >> "); payRate = input.nextLine(); s - idString delimiter - name delimiter payRate System.getProperty("line separator"); name =
name = input.nextLine(); System.out.print("Enter pay rate >> "); payRate - input.nextLine(); s = idString delimiter - name delimiter + payRate = System.getProperty("line separator"); byte[] data = s.getBytes(); ByteBuffer buffer = ByteBuffer.wrap(data); fc.position(id RECSIZE); fc.write(buffer); System.out.print("Enter next ID number or + QUIT to quit »>"); idString - input.nextLine(); fo.close(); catch (Exception e) { System.out.println("Error message: .e);
RandomEmpl... File Edit Format View Help 000, ,00.00 000, ,00.00 000, ,00.00 003, Calhoon, 21.45 004, Lincoln, 11.65 000, ,00.00 000, ,00.00 000, ,00.00 000, ,00.00 000, ,00.00 000, ,00.00 000, ,00.00 012, Winters, 17.25 000, ,00.00 014, Greeley, 21.15 000, ,00.00 000, ,00.00
000, 000, 000, ,00.00 ,00.00 000, ,00.00 000, ,00.00 000, ,00.00 ,00.00 000, ,00.00 000, ,00.00 000, ,00.00 000, ,00.00 000, , 00101, Tony, 11.00 102, Samm, 13.00 103, Loui, 12.43 ,104, Rodd, 11.65 . 000, 000, 105, Hale, 12.33 . 106, Pete, 13.66 107, Port, 12.32 ,00.00 ,00.00 000, ,00.00 ,00.00 000, ,00.00 ,00.00 ,00.00 ,00.00 ,ᎾᎾ , ᎾᎾ ,00.00 000 ,00.00 ,00.00 ,00.00 ,00.00 ,00.00 000 . ,00.00 000, 000 000, 000, 800, 800, 000, 000, 000, Type here to search
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; public class CreateEmployeesRandomFile { public static void main(String[] args) { Scanner input = new Scanner(System.in); Path file = Paths.get("C:\\Users\\antho\\Documents\\316 - Programming|\Random Employees.txt"); String s - "000, ,00.00" . System.getProperty("line.separator"); final int RECSIZE = s.length(); FileChannel fc = null; String delimiter - ","; String idString; int id; String name; I String payRate; final String QUIT = "999"; try fc = (FileChannel)Files.newByteChannel(file, READ, WRITE); System.out.print("Enter employee ID number >> "); idString - input.nextLine(); while(!(idString.equals(QUIT))) { id - Integer.parseInt(idString), System.out.print("Enter name for employee " . id »>"); input.nextLine(); System.out.print("Enter pay rate >> "); payRate = input.nextLine(); s - idString delimiter - name delimiter payRate System.getProperty("line separator"); name =
name = input.nextLine(); System.out.print("Enter pay rate >> "); payRate - input.nextLine(); s = idString delimiter - name delimiter + payRate = System.getProperty("line separator"); byte[] data = s.getBytes(); ByteBuffer buffer = ByteBuffer.wrap(data); fc.position(id RECSIZE); fc.write(buffer); System.out.print("Enter next ID number or + QUIT to quit »>"); idString - input.nextLine(); fo.close(); catch (Exception e) { System.out.println("Error message: .e);
RandomEmpl... File Edit Format View Help 000, ,00.00 000, ,00.00 000, ,00.00 003, Calhoon, 21.45 004, Lincoln, 11.65 000, ,00.00 000, ,00.00 000, ,00.00 000, ,00.00 000, ,00.00 000, ,00.00 000, ,00.00 012, Winters, 17.25 000, ,00.00 014, Greeley, 21.15 000, ,00.00 000, ,00.00
000, 000, 000, ,00.00 ,00.00 000, ,00.00 000, ,00.00 000, ,00.00 ,00.00 000, ,00.00 000, ,00.00 000, ,00.00 000, ,00.00 000, , 00101, Tony, 11.00 102, Samm, 13.00 103, Loui, 12.43 ,104, Rodd, 11.65 . 000, 000, 105, Hale, 12.33 . 106, Pete, 13.66 107, Port, 12.32 ,00.00 ,00.00 000, ,00.00 ,00.00 000, ,00.00 ,00.00 ,00.00 ,00.00 ,ᎾᎾ , ᎾᎾ ,00.00 000 ,00.00 ,00.00 ,00.00 ,00.00 ,00.00 000 . ,00.00 000, 000 000, 000, 800, 800, 000, 000, 000, Type here to search