Question: import java.io.BufferedReader; import java.io.FileInputStream; import java.io.InputStreamReader; public class FileOperator { /*This method reads the file located in the given file path, * parses the file
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.InputStreamReader;
public class FileOperator {
/*This method reads the file located in the given file path,
* parses the file content to Term objects,
* stores the terms in an array,
* returns the term array
*/
public Term[] readTerms(String filePath) {
try {
BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(filePath), "UTF-8"));
int fileSize = Integer.parseInt(br.readLine());
Term [] termList = new Term[fileSize];
for (int i = 0; i < fileSize; i++) {
String line = br.readLine().trim();
int weight = Integer.parseInt(line.split("\t")[0]);
String text = line.split("\t")[1];
Term w = new Term(weight, text); //How do you fix this?
termList[i] = w;
}
br.close();
return termList;
} catch (Exception e) {
e.printStackTrace();
}
return new Term [0];
}
}
public class Term {
/*Define the appropriate fields and constructors for Term class.
* Hint: You can take the Term instance in the FileOperator class as reference.
*/
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
