I am trying to assign the output of this code as a new string variable, currently, the output is printed from a for loop, I am using split/tokens to change each "," to a ">". The output I want is correct, but I would like to use a delimiter ">" afterwards to separate each line into separate categories. Here is my code...
import java.io.File;
import java.io.IOException;
import java.util.Scanner;
public class tests {
public static void main(String[] args) throws IOException {
String fileContent = "";
String number = "";
try {
Scanner file = new Scanner(new File("netflix_titles.txt"));
while(file.hasNextLine()){
fileContent = fileContent.concat(file.nextLine() + "\n");
}
String[] tokens = fileContent.split(",(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)", -1);
for(String t : tokens) {
System.out.print("> " + t);
}
}
catch(Exception e){
System.out.println("invalid input");
}
}
}
The first line of the file is
s1,TV Show,3%,,"João Miguel, Bianca Comparato, Michel Gomes, Rodolfo Valente, Vaneza Oliveira, Rafael Lozano, Viviane Porto, Mel Fronckowiak, Sergio Mamberti, Zezé Motta, Celso Frateschi",Brazil,"August 14, 2020",2020,TV-MA,4 Seasons,"International TV Shows, TV Dramas, TV Sci-Fi & Fantasy","In a future where the elite inhabit an island paradise far from the crowded slums, you get one chance to join the 3% saved from squalor."
After the code is compiled it looks like
s1> TV Show> 3%> > "João Miguel, Bianca Comparato, Michel Gomes, Rodolfo Valente, Vaneza Oliveira, Rafael Lozano, Viviane Porto, Mel Fronckowiak, Sergio Mamberti, Zezé Motta, Celso Frateschi"> Brazil> "August 14, 2020"> 2020> TV-MA> 4 Seasons> "International TV Shows, TV Dramas, TV Sci-Fi & Fantasy"> "In a future where the elite inhabit an island paradise far from the crowded slums, you get one chance to join the 3% saved from squalor."
I would like to be able to use a ">" delimiter afterwards to create an object for each line with individual constructors split by the >. Since it is only being outputted through a for loop, I am not sure how to use a delimiter after its been outputted. Sorry if this is confusing I am not sure how to correctly word this.