For this assignment, you will “starter” code. After you finish, your code should access an existing text file that you have created, create an input stream, read the contents of the text flie, sort and store the contents of the text file into an ArrayList, then write the sorted contents via an ouput stream to a separate output text file. and the following Java™ code into a JAVA source file in NetBeans: import java.io.BufferedReader; import java.io.BufferedWriter; public class Datasort { public static void main (String [] args)  { File fin =      // input  file File fout =    // create an out file // Java FileInputStream class obtains input bytes from a file FileInputStream fis = new FileInputStream(fin); // buffering characters so as to provide for the efficient reading of characters, arrays, and lines BufferedReader in = new BufferedReader(new InputStreamReader(fis)); // declare an array in-line, ready for the sort String aLine; ArrayList al = new ArrayList (); int i = 0; while ((aLine = in.readLine()) != null) { // set the sort  for values is greater than 0 Collections.sort(al);    // sorted content to the output  file { System.out.println(s); } // close the 2 files } } code as indicated in the comments.

This assignment requires you to write Java code that accesses an existing text file, reads its contents, sorts and stores those contents into an ArrayList, and then writes the sorted contents to a separate output text file.

To start, you will need to import the necessary classes, specifically the `BufferedReader` and `BufferedWriter` classes. These classes provide methods for reading and writing text files, respectively. After importing these classes, you will need to create a class called `Datasort`.

Inside the `Datasort` class, you should define a `main` method, which is the entry point for your program. This method takes in an array of strings as arguments, which will be used to pass any command-line arguments to the program.

First, you need to declare two `File` objects to represent the input and output files. The `fin` object represents the input file, and the `fout` object represents the output file. You will need to assign appropriate file paths to these objects.

Next, you need to create a `FileInputStream` object called `fis` by passing the `fin` object as an argument. The `FileInputStream` class obtains input bytes from a file. This object will be used to read the input file.

After that, you need to create a `BufferedReader` object called `in` by passing a `InputStreamReader` object that wraps the `fis` object. The `BufferedReader` class provides efficient reading of characters, arrays, and lines from the `InputStreamReader`. This object will be used to read the contents of the input file.

Now, you can start reading the contents of the input file. You can use a `while` loop to read each line of the file. Inside the loop, you will assign each line to a string variable called `aLine`. The `readLine` method of the `BufferedReader` class returns the next line of text from the input file. The loop will continue as long as there are more lines to read.

Inside the loop, you will need to sort the contents of the file. To do this, you can call the `sort` method of the `Collections` class, passing the `al` object as an argument. This will sort the elements of the `al` object in ascending order.

After sorting the contents, you can use a `for-each` loop to iterate over the sorted elements of `al` and print each element to the console using `System.out.println`. This will display the sorted contents of the input file.

Finally, you need to close the input and output files. You can do this by calling the `close` method of the `BufferedReader` and `BufferedWriter` objects, respectively.

Note that the code provided is incomplete and there are parts that need to be filled in to complete the assignment. You need to provide the file paths for the input and output files, and also write the code to write the sorted contents to the output file.

Need your ASSIGNMENT done? Use our paper writing service to score better and meet your deadline.


Click Here to Make an Order Click Here to Hire a Writer