Halloween 1978 R 47 93 7.7
Hard Rain 1998 R 19.819 95 5.2
Men in Black 1997 PG-13 250.147 98 7.4
I Know What You Did Last Summer 1997 R 72.219 100 6.5
Volcano 1997 PG-13 47.474 102 5.8
Chasing Amy 1997 R 12.006 105 7.9
Terminator 1984 R 36.9 108 7.7
Grease 1978 PG 181.28 110 7.3
And my code is not working right, i tried playing around with it, but im not getting anywhere.
I am currently not finding the file in eclipse but i have been testing around in java and im getting....
So i copied all the data in the excel document and put it in Notepad, and i could read the file fine.
But when i tried to read it as a csv file, it gave me this
Exception in thread "main" java.util.NoSuchElementException
at java.util.Scanner.throwFor(Scanner.java:838)
at java.util.Scanner.next(Scanner.java:1461)
at java.util.Scanner.nextInt(Scanner.java:2091)
at java.util.Scanner.nextInt(Scanner.java:2050)
at Tester.main(Tester.java:55)
This is the scanner part of my program here....
Scanner s = null;
try {
s = new Scanner(new File("MOVIES.csv"));
} catch (FileNotFoundException e) {
System.out.println("File \"Movies.csv\" not found in the current directory.");
System.out.println("Exiting the program.");
System.exit(0);
}
List<Movie> theList = new ArrayList<Movie>();
StringBuilder sb = new StringBuilder();
while (s.hasNext()) {
while (s.hasNext() && !s.hasNextInt()) {
sb.append(s.next()).append(" ");
}
String title = sb.toString().trim();
int year = s.nextInt(); //this is line 55
String rating = s.next();
double profit = s.nextDouble();
int length = s.nextInt();
double popularity = s.nextDouble();
theList.add(new Movie(title, year, rating, profit, length, popularity));
sb.setLength(0);
}
s.close();
So i dont know why i can read it as a txt file but not a csv file????
I have not been successful with file reading and i could use some help. Thanks
This post has been edited by jaybfox4: 25 May 2009 - 05:31 PM

New Topic/Question
Reply




MultiQuote




|