Question: Task 2 : Perform the following file and array - based tasks: a . In your code create a file named assignment 1 . txt

Task 2: Perform the following file and array-based tasks:
a. In your code create a file named assignment1.txt.
i. Correct: File fileName = new File("assignment1.txt");
i. Correct because the file will be created in your current working directory.
ii. Incorrect: File fileName = new File("C:/Dev/assignment1.txt");
i. Incorrect because it includes the path name when creating the file.
b. Open the file for writing.
i. PrintWriter resultsFile = new PrintWriter (fileName);
c. Write the values in the two arrays to the file in sorted order.
i. To create the file of sorted values, the sort MUST be done manually.
i. DO NOT move the values into a 3rd array, sort, then write to the file.
ii. See Must Do and Tips below for proper approach.
ii. Write one value on each line in the file.
iii. Display each value as you write it to the file.
iv. See the output below where it shows Writing values to file for an example.
d. Close the file.
i. Make sure assignment1.txt appears on your hard drive in the workspace directory.
ii. See the Must Do and Tips section for help with finding the file on your hard driv

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!