this code keeps producing an error and I am unsure how to proceed. results below import java.nio.file.*; import java.io.

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

this code keeps producing an error and I am unsure how to proceed. results below import java.nio.file.*; import java.io.

Post by answerhappygod »

this code keeps producing an error and I am unsure how
to proceed. results below
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("C:\\Users\\antho\\Documents\\Visual Studio 2022\\Code
Snippets\\JavaScript\\My Code Snippets\\InStateCusts.txt");
Path outOfStateFile =
Paths.get("C:\\Users\\antho\\Documents\\Visual Studio 2022\\Code
Snippets\\JavaScript\\My Code
Snippets\\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";

createEmptyFile(inStateFile, s);
createEmptyFile(outOfStateFile, s);


try
{

fcIn =
(FileChannel)Files.newByteChannel(inStateFile, CREATE,
WRITE);
fcOut =
(FileChannel)Files.newByteChannel(outOfStateFile, CREATE,
WRITE);

System.out.print("Enter customer
account number >> ");
idString = input.nextLine();

while(!(idString.equals(QUIT)))
{
id =
Integer.parseInt(idString);

System.out.print("Enter
name of customer >> ");
name =
input.nextLine();
StringBuilder sb = new
StringBuilder(name);

sb.setLength(NAME_LENGTH);
name =
sb.toString();
System.out.print("Enter
state >> ");
state =
input.nextLine();

System.out.print("Enter
balance >> ");
balance =
input.nextDouble();
input.nextLine();
DecimalFormat ddf = new
DecimalFormat(BALANCE_FORMAT);

s = idString + delimiter
+ name + delimiter + state + delimiter + df.format(balance) +
System.getProperty("line.separator");
byte data[] =
s.getBytes();
ByteBuffer buffer =
ByteBuffer.wrap(data);


if(state.equals(HOME_STATE))
{

fcIn.position(id * RECSIZE);

fcIn.writer(buffer);
}
else
{

fcOut.position(id * RECSIZE);

fcOut.writer(buffer);
}

fcIn.close();

fc.Out.close();
}
}
catch (Exception e)
{
System.out.println("Error
message: " + e);

}
public static void createEmptyFile(Path file,
String s)
{
final int NUMRECS = 1000;
try
{
OutputStream outputStr =
new BufferedOutputStream(Files.newOutputStream(file,CREATE));
BufferedWriter writer =
new BufferedWriter(new OutputStreamWriter(outputStr));

for(int count = 0; count
< NUMRECS; ++count)

writer.write(s, 0, s.length());
writer.close();

}
catch(Exception e )
{

System.out.println("Error message: " + e);
}
}

}
}
This Code Keeps Producing An Error And I Am Unsure How To Proceed Results Below Import Java Nio File Import Java Io 1
This Code Keeps Producing An Error And I Am Unsure How To Proceed Results Below Import Java Nio File Import Java Io 1 (159.15 KiB) Viewed 42 times
} G CreateFilesBasedOnState.java CAUsersantho\Documents\Visual Studio 2022\Code Snippets JavaScript My Code Snippets - GRASP CSD Java) X Elle Edit View Bulld Project Settings Tools Window Help * XnAERULU+PE All Files - Sort By Name 93 public static void createEmptyFile(Path file, String s) 94 incit <L 95 tiral int MUMRECS - 1000; de Snippets JavaScript My Code Snippets - 96 try CreateEmployeesRandomFileAlternative 97 ( CreateEmployeesRandomFileAnother Alte 98 OutputStrean outputStr = new BufferedoutputStream(Files.newoutputStrean(file,CREATE)); Create EmployeesRandomFileAnotherAlty 99 BufferedWriter writer = new Bufferedariter(new OutputStreamkriter(outputstr)); CreateEmpty EmployeesFile.class 100 101 CreateEmpty EmployeesFile.java for(int count - @; count < MUMRECS; tcount) CreateFilesBasedon State.class 102 writer.write(s, 0, s.length()); CreateFilesBasedon State.ava 103 writer.close(); 104 } CreateOneRandomAccessRecord.class 105 CreateOneRandom AccessRecord.java catch(Exception e) 106 { CreatePolicies.class 107 CreatePolicies.java System.out.println("Error message: "+e); " 100 CreatePolicles2.class 109 } CreatePolicies2.java 110 Create Spa Services.class 111 } CreateSpa Services.java CreatingPath.java Customer.class WriteEmployee... ReadEmploye... ReadingEmploy... Random Access... CreateEmpty... CreateOneRa... CreateEmploye... ReadEmployee... ReadEmployec... CreateFilesBas. Customer.java Customer Account.class Compile Messages JGRASP Messages Run I/O Interactions Customer Account java Customerlist.txt Stop Data.txt ----GRASP exec: javac - CreateFilesBasedonState.java DataDemo.class Clear CreatelilesBasedonState.java:93: error: illegal start of expression DataDemo.java public static void createEmptyFile(Path file, Strings) Copy Declare TwoEmployees.class Declare TwoEmployees.java CreateFilesBasedonState.java:112: error: class, interface, enun, or record expected Decreasingloop.class } Decreasingloop.java 2 errors DeliveryDate.class Delivery Date Java ----GRASP wedge2: exit code for process is 1. DemoArray.class ----GRASP: operation complete. Demokrray.java DemoArray3.class DemoArray3 Java DemoBlock.class Browse Find Debug Workbench Line:94 Col:B Code: VP4 Type here to search o O B! Top:93 VOLK ASSAM 5/17/2022 G o 0 g 69°F
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply