Hello I have a working program that reads a txt file (name, id, email, password) and writes only name and email to an output file of .html extension...
my trouble is I have the program working all under 1 class.. but my requirements is I need multiple classes.. 1 for processing, 1 for reading, 1 for writing. How would you recommend I break up my file? Im kind of confused and any guidance is appreciated Thank you
import java.io.*;
public class test {
public static void main(String[] args) throws Exception{
// define the path to your text file
System.out.println("Enter your file name \n");
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
String myFilePath = in.readLine();
String file1 = (myFilePath + ".txt");
System.setOut(new PrintStream(new FileOutputStream(myFilePath + ".html")));
// read and parse the file
try {
BufferedReader br = new BufferedReader(new FileReader(new File(file1)));
String line, name, email;
// read through the first two lines to get to the data
line = br.readLine();
line = br.readLine();
while ((line = br.readLine()) != null) {
if (line.contains("|")) {
// do line by line parsing here
line = line.trim();
// split the line
String[] parts = line.split("[|]");
// parse out the name and email
name = parts[1].trim();
email = parts[2].trim();
// rearrange the name
String[] nParts = name.split(" *");
if (nParts.length == 3) {
name = nParts[1] + " " + nParts[2] + " " + nParts[0];
} else {
name = nParts[1] + " " + nParts[0];
}
// all done now, let's print the name and email
System.out.println(email + " " + name);
}
}
br.close();
} catch (Exception e) {
System.out.println("There was an issue parsing the file.");
}
}
}