Results 1 to 1 of 1
Thread: CSV File read error!
- 10-27-2011, 08:45 PM #1
Member
- Join Date
- Nov 2010
- Posts
- 66
- Rep Power
- 0
CSV File read error!
I have an assigment that reads data from a csv file and outputs it on the screen.. My teacher gave me the code and I fixed some errors.. It compiles fine, but when I run the program, I get the following error:
Error: For input string: "statusbar"
Here is the code I have:
I have no idea what the statusbar error means.. any help will be much appreciated! :)Java Code:import java.io.BufferedReader; // Imports bufferedreader import java.io.DataInputStream; // Imports datainputstream import java.io.FileInputStream; // Imports fileinputstream import java.io.InputStreamReader; // Imports inputstreamreader public class FileRead3 // The class is named "FileRead3" { public static double convertJDN(String date) // This method takes a value for "date" and formats it { String[] str = date.split("/"); // Adds a slash into the string int Y = Integer.parseInt(str[2]); // Formats the string to have the year at the last place int M = Integer.parseInt(str[0]); // Formats the string to have the month at the first place int D = Integer.parseInt(str[1]); // Formats the string to have the day at the second place double JDN = (1461 * (Y + 4800 + (M - 14) / 12)) / 4 + (367 * (M - 2 - 12 * ((M - 14) / 12))) / 12 - (3 * ((Y + 4900 + (M - 14) / 12) / 100)) / 4 + D - 32075; // Formula to calculate the date return JDN; // Returns the value of "JDN" to the method that called it } public static void main(String[] args) // Main method { try // Try block { FileInputStream fstream = new FileInputStream("FileRead3.csv"); // Creates an inputstream for the file specified DataInputStream in = new DataInputStream(fstream); // Creates a datainputstream to collect the data in the file BufferedReader br = new BufferedReader(new InputStreamReader(in)); // Creates a bufferedreader that stores that value of "in" in "br" String strLine; // The string is initialized while((strLine = br.readLine()) != null) // Reads the values from the files as long as there is a value { // System.out.println(strLine); String strAy[] = strLine.split(","); // Creates a new array of string type and stores the values of the variable "strLine" with commas for(int i=0; i<strAy.length; i++) // For loop that loops from 0 to the number of elements in the array "strAy" { if(strAy[i].contains("/")) // Checks if any index of the array has a slash { double jdn = convertJDN(strAy[i]); // Sends the value of the specific index to the method "convertJDN" and stores whatever is returned in the variable "jdn" System.out.print(" " + jdn); // Prints out the value of jdn } else // If none of the indexes contain a slash, the program executes the following block of code { Double d; // Initialized d try // Try block { d = Double.parseDouble(strAy[i]); // Takes the index of the array "strAy" and converts it into a double and then stores it into the variable d System.out.print(" " + d); // Outputs the value of d } catch(NumberFormatException nfe) // Tries to catch an error with the format of a number { System.out.print(" " + strAy[i]); // Prints out the index which is causing the error } } } System.out.println(); // Skips a line } in.close(); // Closes the inputstreamreader } catch(Exception e) // Tries to catch an error { System.err.println("Error: " + e.getMessage()); // Prints out the message "Error: " and whatever the error is } } }
Similar Threads
-
Excel file read error
By Asvin in forum New To JavaReplies: 10Last Post: 04-28-2011, 10:01 PM -
Getting error when trying to read file into float array
By tinaman in forum New To JavaReplies: 7Last Post: 04-26-2011, 03:27 PM -
Error printing from Read in file.
By Accendo in forum New To JavaReplies: 6Last Post: 01-21-2011, 06:07 AM -
how to read openproj(Projity) file i.e. ,POD file(Project Management file)
By mahendra.athneria in forum New To JavaReplies: 0Last Post: 02-11-2009, 09:53 AM -
How to read a text file from a Java Archive File
By Java Tip in forum Java TipReplies: 0Last Post: 02-08-2008, 09:13 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks