I would like to read data from a tv file, store in an arraylist and then print out the data unto my screen.
package Testing;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.FileWriter;
import java.util.ArrayList;
import java.util.Scanner;
public class Options {
private static ArrayList<Object> tv1Holder = new ArrayList<Object>();
private static Scanner inputData = new Scanner(System.in);
public static void main (String[] st){
System.out.println("Hi och welcome to TV");
System.out.println("What do you want to do?");
System.out.println("1) Show guide for tv1");
System.out.println("2) Show guide for tv2");
System.out.println("3) Show and handle recordings");
System.out.println("End");
int intakeValue = inputData.nextInt();
switch (intakeValue) {
case 1:showTv1();
break;
case 2: showTv2();
break;
case 3: showAndHandleRecordings();
break;
case 4: end();
default:
break;
}}
private static void showTv1(){
Scanner scanIn = null;
try{
scanIn = new Scanner(new FileReader("tv1.txt"));
while (scanIn.hasNextLine()){
String[] s = scanIn.nextLine().split(" ");
for(String newSValues: s){
System.out.println(tv1Holder.add(newSvalues));
}
}
}
catch (Exception e) {
System.out.println("Error:" + e.getMessage());
}
}
tv1.txt file contains a list of tv shows which i want to store in an arraylist. As of now the code only prints out true 'x' amount of times.