Question

In: Computer Science

When using random access files in Java, the programmer is permitted to create files which can...

When using random access files in Java, the programmer is permitted to create files which can be read from and written to random locations. Assume that a file called "integers.dat" contains the following values: 25 8 700 284 63 12 50 Fill in blanks: You are required to write the following Java code statements: (a) create a new stream called, blueray, which allows the program to read from and write to the file, "integers.dat." _____________________ (b) Write a statement which will move the file pointer to the number, 700. _____________________ (c) Write a statement to display the contents currently pointed to. _____________________ (d) Write a statement which will move the file pointer from its current position, directly to the end of the file. _____________________ (e) Append the value 999999 to the file. _____________________

Solutions

Expert Solution

(a) create a new stream called, blueray, which allows the program to read from and write to the file, "integers.dat."

RandomAccessFile blueray = new RandomAccessFile("E:/chegg/integers.dat", "rw");

Create a new RandomAccessFile stream specifying path of the file and the mode of file

(b) Write a statement which will move the file pointer to the number, 700.

blueray.seek(2);

seek() helps in setting the file pointer. Since 700 is found at 2nd we'll set seek to 2.

(c) Write a statement to display the contents currently pointed to.

System.out.println("" + blueray.readInt());

readInt() helps in reading the integers from file and println statement displays them

(d) Write a statement which will move the file pointer from its current position, directly to the end of the file.

blueray.seek(blueray.length());

length() gives the length of file, and use seek() to point the it => points to the end of file

(e) Append the value 999999 to the file.

blueray.writeInt(9999999);

writes 999999 to the location pointed by the file pointer


Related Solutions

What is true about Random Access Files? Check all that apply. 1. The program can read...
What is true about Random Access Files? Check all that apply. 1. The program can read file data anywhere the read location is positioned. 2. Data must be sorted to to use random access functions. 3. Data can be read in any order specified in the program. 4. seekp and seekg can be used to access files by a given position.
describe the mechanism that supports random file access in Java.
describe the mechanism that supports random file access in Java.
(Using Java) create a class that can identify a palindrome. A palindrome is defined as -...
(Using Java) create a class that can identify a palindrome. A palindrome is defined as - A string of characters that reads the same from left to right as its does from right to left - Example: Anna, Civic, Kayak, Level, Madam - To recognize a palindrome, a queue can be used in conjunction with a stack o A stack can be used to reverse the order of occurrences o A queue can be used to preserve the order of...
java program Create a program that creates and prints a random phone number using the following...
java program Create a program that creates and prints a random phone number using the following format: XXX-XXX-XXXX. Make sure your output include the dashes.  Do not let the first three digits contain an 8 or 9 (HINT: do not be more restrictive than that) and make sure that the second set of three digits is not greater than 773. Helpful Hint:   Think though the easiest way to construct the phone number. Each digit does do not have to be determined...
Create a program using Java. Create two different 3D arrays with random numbers. (lets name them...
Create a program using Java. Create two different 3D arrays with random numbers. (lets name them array1 and array 2) Add the two 3Darrays together and then get the average. Save the average on a separate 3D array.(lets name it array3) Then add array1 and array3 then get the average Save the average on a separate 3Darray(lets name it array 4) Then add array2 and array3 then get the average Save the average on a separate 3Darray (lets name it...
The project description: As a programmer, you have been asked to write a Java application, using...
The project description: As a programmer, you have been asked to write a Java application, using OOP concepts, for a Hospital with the following requirements: • The Hospital has several employees and each one of them has an ID (int), name (string), address (string), mobile phone number (string), email (string) and salary (double) with suitable data types. • The employees are divided into: o Administration staff: who have in addition to the previous information their position (string). o Doctor: who...
As a programmer, you have been asked to write a Java application, using OOP concepts, for...
As a programmer, you have been asked to write a Java application, using OOP concepts, for a Hospital with the following requirements: • The Hospital has several employees and each one of them has an ID (int), name (string), address (string), mobile phone number (string), email (string) and salary (double) with suitable data types. • The employees are divided into: o Administration staff: who have in addition to the previous information their position (string). o Doctor: who have also a...
Using import java.util.Random, create a simple java code that populates an array with 10 random numbers...
Using import java.util.Random, create a simple java code that populates an array with 10 random numbers and then outputs the largest number.
When using Microsoft Visio or Access, what is the importance of data validation, and how can...
When using Microsoft Visio or Access, what is the importance of data validation, and how can user data entry errors be reduced or eliminated?
Create a calculator in java without using the math library which converts an integer into a...
Create a calculator in java without using the math library which converts an integer into a hexadecimal number.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT