Code:
public static void createMovie() {
String fileName = "C:\\Users\\kat7r\\eclipse-workspace\\Final OOPs project\\src\\movielist.txt";
File movieFile = new File(fileName);
try {
Scanner inputStream = new Scanner(movieFile);
inputStream.next();
while (inputStream.hasNext()) {
String movieArgs = inputStream.next();
String[] splitData = movieArgs.split(",");
System.out.println(movieArgs);
//int priority = Integer.parseInt(splitData[0]);
//System.out.println("Priority: "+priority);
}
} catch(FileNotFoundException e) {
System.out.println("File not found.");
Expected output:
Priority,Name,Genre,Length,Rating
1,Inception,Science Fiction,2.47,8
2,Shawshank Redemption,Drama,2.37,9
3,Coco,Fantasy,1.82,8
4,Lord of the rings,Fantasy,3.8,9
5,Thor: Ragnarok,Fantasy,2.17,8
Actual output;
1,Inception,Science
Fiction,2.47,8
2,Shawshank
Redemption,Drama,2.37,9
3,Coco,Fantasy,1.82,8
4,Lord
of
the
rings,Fantasy,3.8,9
5,Thor:
Ragnarok,Fantasy,2.17,8
Comments:
Essentially the spaces are causing the IDE to start a new line. I tried using .nextLine
but that didn't help. Tried going online as well.