java
java myeclipse. i am trying to load data from csv file and add all the numbers in 10 column
scanning the csv document using scanner class i get error at int number= Integer.parseInt(values[9]); ERROR: Exception in thread "main" java.lang.NumberFormatException: For input string: "207"" at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65) at java.lang.Integer.parseInt(Integer.java:580) at java.lang.Integer.parseInt(Integer.java:615) at netex.netEx.main(netEx.java:24) package example; import java.util.*; import java.io.*; public class myex { public static void main(String[] args) { String fileName= "pedestrain.csv"; File file = new File(fileName); Scanner inputStream; try { inputStream = new Scanner(file); inputStream.next(); double sum=0; double numberOfEntries=0; while (inputStream.hasNext()) { String data= inputStream.next(); String values []= data.split(","); int number= Integer.parseInt(values[9]); sum = sum + number; numberOfEntries++; } inputStream.close(); System.out.println(sum); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }
What's written in the File you want to read? It seems like that is no string that's only made out of numbers.
Related Links
Problem signing jars for web applet
Automatically Updating Database Schema For Java Project's Unit Tests
Java, How to Instance HttpCookie from a String, any convenient ways?
For improving my programming skills I want to follow “learn a new language a year”. What we can learn in 2011
Java Networking Problem: java.net.ConnectException: Connection refused: connect
How to execute task and show its progress in spring web flow
Design Help! java generics in a enum factory transformer!
editing the contents of an array list
Dynamically add Textbox to Window when checkbox is checked
Java Exceptions: exception myException is never thrown in body of corresponding try statement
How to store values in MONGO DB using JAVA?
Why the image is not displayed in the imageItem?
Maven and AppServer dependency management best practice
How to delete obsolete workspace in RAD?
MySQL connection in Java problem
Java Graphics Multiple Classes