Question: JAVA, need help with splitting lines and strings and implementing them into ArrayList import java.util.ArrayList; import java.util.Scanner; import java.io.PrintWriter; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.FileNotFoundException;

JAVA, need help with splitting lines and strings and implementing them into ArrayList

import java.util.ArrayList;

import java.util.Scanner;

import java.io.PrintWriter;

import java.io.FileInputStream;

import java.io.FileOutputStream;

import java.io.FileNotFoundException;

import java.io.IOException;

/**

* Opens and reads the contents of the input file specified in fileName. The input file is read

* line by line. Each line is split into words and punction (excluding the apostrophe) and

* stored in an ArrayList of Strings. These ArrayLists representing the line are stored in an

* ArrayList of ArrayLists of Strings. Specifically, they are put in the ArrayList fileByLine

* that is passed in as a parameter.

*

* For example, a file containing the following:

* Lorem ipsum dolor sit amet, consectetur adipiscing elit. Don'ec elementum tortor in mauris

* consequat vulputate.

*

* Would produce an ArrayList of ArrayLists containing 2 ArrayLists of Strings.

* The first ArrayList would contain:

* "Lorem", "ipsum", "dolor", "sit", "amet", ",", "consectetur", "adipiscing", "elit", ".",

* "Don'ec", "elementum", "tortor", "in", "mauris"

* The second Arraylist would contain:

* "consequat", "vulputate", "."

*

* Note 1: The text file is assumed to be UTF-8.

* Note 2: There are no assumption about the length of the file or the length of the lines.

* Note 3: All single quotes (') are assumed to be apostrophes.

*

* When opening the file, any FileNotFoundException is caught and the error message

* "Exception: File 'fileName' not found." followed by a new line is output,

* where fileName is the name of the file that the method attempted to open.

*

* @param fileName The name of the input text file to parse.

* @param fileByLine Reference to ArrayList to contain the contents of the file line by line,

* where each line is an ArrayList of Strings.

* @throws IOException if an I/O error occurs when closing the file. FileNotFoundException is

* caught when opening the file.

*/

public static void readInputFile(String fileName,

ArrayList > fileByLine) throws IOException {

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!