Can someone please help me? I'm having trouble with this assignment and have been stuck trying to figure it out for over an hour.
Here's the assignment details below:
For this assignment, you will develop "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.
Copy and paste 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<String> al = new ArrayList<String> ();
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
}
}
import java.io.*;
import java.util.*;
public class Datasort {
public static void main (String [] args) {
File fin = new File("input.txt"); // input file
File fout = new File("output.txt"); // create an out file
// Java FileInputStream class obtains input bytes from a file
FileInputStream fis;
ArrayList<String> al= new ArrayList<String> ();;
try {
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;
while ((aLine = in.readLine()) != null) {
al.add(aLine);
}
in.close();
} catch (FileNotFoundException ex) {
System.out.println("File not found");
}
catch (IOException ex) {
System.out.println("File read error");
}
// set the sort for values is greater than 0
Collections.sort(al); // sorted content to the output file
for(int i=0;i<al.size();i++){
// write in console
System.out.println(al.get(i));
}
// write sorted data in file
FileWriter fileWriter = null;
BufferedWriter writer = null;
try {
fileWriter = new FileWriter(fout);
if(fout.exists()==false){
fout.createNewFile();
}
writer=new BufferedWriter(fileWriter);
for(int i=0;i<al.size();i++){
// write sorted array data in file
writer.write(al.get(i));
// write new in file , except last line
if(i<al.size()-1){
writer.write("\n");
}
}
writer.close();
fileWriter.close();
} catch (IOException ex) {
System.out.println("File writing error.");
}
}
}


Can someone please help me? I'm having trouble with this assignment and have been stuck trying...
Having trouble with my code, it keeps giving me an error every time I run it. Can someone please help me understand what I'm doing wrong? *********CODE*************** // Java program to read the file contents, sort it and output the sorted content to another file import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.File; import java.io.FileInputStream; import java.io.FileWriter; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.Collections; public class Datasort { public static void main(String[] args) throws IOException { File fin = new File("input.txt");...
Help! Not sure how to create this java program to run efficiently. Current code and assignment attached. Assignment :Write a class Movies.java that reads in a movie list file (movies.txt). The file must contain the following fields: name, genre, and time. Provide the user with the options to sort on each field. Allow the user to continue to sort the list until they enter the exit option. ---------------------------------------------------------- import java.util.*; import java.io.*; public class Movies { String movieTitle; String movieGenre;...
please help. About java tcp. this is what i have so far. how to convert input value into ASCII sequence For example the message: “Hello World” would become “Ifmmp!Xpsme”For example the message: “Hello World” would become “Ifmmp!Xpsme”in server.java. Client.java: import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintStream; import java.net.Socket; import java.net.SocketTimeoutException; public class Client { public static void main(String[] args) throws IOException { Socket client = new Socket("127.0.0.1", 20006); client.setSoTimeout(10000); BufferedReader input = new BufferedReader(new InputStreamReader(System.in)); PrintStream out...
Hello can somebody please help me with Project 15-3 File Cleaner assignment? This project is to be done while using Java programming. Here are what the assignment says… Create an application that reads a file that contains an email list, reformats the data, and writes the cleaned list to another file. Below are the grading criteria… Fix formatting. The application should fix the formatting problems. Write the File. Your application should write a file named prospects_clean.csv. Use title case. All...
QUESTION The ReadFile class opens and reads a text file. The WriteFile class opens and writes to a file. Compile and run these programs. There are several ways to read/write text files. The examples shown here are just one way of achieving this. Look at the API for the BufferedReader class. The readline() method is a simple way to read the text file line by line. It returns null when the end of the file has been reached. https://docs.oracle.com/javase/8/docs/api/java/io/BufferedReader.html Look...
Please answer question correctly and show the result of the working code. The actual and demo code is provided .must take command line arguments of text files for ex : input.txt output.txt from a filetext(any kind of input for the text file should work as it is for testing the question) This assignment is about using the Java Collections Framework to accomplish some basic text-processing tasks. These questions involve choosing the right abstraction (Collection, Set, List, Queue, Deque, SortedSet, Map,...
Exception handling is a powerful tool used to help programmers understand exception errors. This tool separates the error handling routine from the rest of the code. In this application, you practice handling exception errors. You use sample code that was purposefully designed to generate an exception error, and then you modify the code so that it handles the errors more gracefully. For this Assignment, submit the following program: The following code causes an exception error: import java.io.BufferedReader; import java.io.IOException; import...
Please complete the give code (where it says "insert code here") in Java, efficiently. Read the entire input one line at a time and then output a subsequence of the lines that appear in the same order they do in the file and that are also in non-decreasing or non-increasing sorted order. If the file contains n lines, then the length of this subsequence should be at least sqrt(n). For example, if the input contains 9 lines with the numbers...
I need help understanding this programming assignment. I do not
understand it at all. Someone provided me with the code but when I
run the code on eclipse it gives an error. Please explain this
assignment to me please.
Here is the code:
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class TextEditor {
public static List<String> lines = new
ArrayList<String>();
public static void main(String[] args) throws IOException
{
Scanner s = new...
Java only. Thanks These questions involve choosing the right abstraction (Collection, Set, List, Queue, Deque, SortedSet, Map, or SortedMap) to EFFICIENTLY accomplish the task at hand. The best way to do these is to read the question and then think about what type of Collection is best to use to solve it. There are only a few lines of code you need to write to solve each of them. Unless specified otherwise, sorted order refers to the natural sorted order...