Professional Documents
Culture Documents
TP09 Eng
TP09 Eng
Input/Output Page 1
In this lab, your will be developing a command line application to filter a text file by
deleting the words specified by the user via the command line. The lab. is composed of
several phases;
1. Passing parameters: It allows the user to specify via the command line the following
parameters:
The path of the file to be processed.
The words to deleted.
For example, to filter the content of the file my_file.txt by deleting all the pronouns,
the user must write the following command;
2. Read File Content: in Java there are several methods that can be used to read the file
content. We list some of them below:
a. Using the methods in Paths, Files and StandardCharsets classes in the
package nio JDK 7.
Path p = Paths.get(file_path);
List<String> lines = Files.readAllLines(p, StandardCharsets.UTF_8);
Path p = Paths.get(file_path);
BufferedReader reader = Files.newBufferedReader(p);
Stream<String> lines = reader.lines();
3. Filter file content: using the method replaceAll in class String or the method
filter in the Stream.
4. Write content to a file: in Java there are several methods that allow you to write data
into a file;
a. Using the methods in the Paths, Files and StandardCharsets classes
in JDK 7
b. Using the methods in the BufferedWriter class
Path p = Paths.get(file_path);
BufferedWriter writer = Files.newBufferedWriter(p)
writer.write(line)