简体   繁体   中英

Preview truncated at 256 rows while reading csv file in java

I am trying to read the contents of a csv file having around 2000 columns and 7 rows. I am getting following error.

Exception in thread "main" java.lang.NumberFormatException: For input string: "Preview truncated at 256 rows"
at sun.misc.FloatingDecimal.readJavaFormatString(FloatingDecimal.java:2043)
at sun.misc.FloatingDecimal.parseDouble(FloatingDecimal.java:110)
at java.lang.Double.parseDouble(Double.java:538)
at java.lang.Double.valueOf(Double.java:502)

Please find the code below

   import java.io.BufferedReader;
   import java.io.FileReader;
   import java.io.IOException;
   import java.util.ArrayList;

   import org.apache.commons.math3.analysis.function.Log;

    public class GoogleFailureGenerator{    
    private ArrayList<Long>hostID = new ArrayList<Long>();  
    private ArrayList<Double>MTBF = new ArrayList<Double>();
    private ArrayList<Double>MTTR = new ArrayList<Double>();
    private ArrayList<Double>SD_TBF = new ArrayList<Double>();
    private ArrayList<Double>Var_TBF = new ArrayList<Double>();
    private ArrayList<Double>SD_TTR = new ArrayList<Double>();
    private ArrayList<Double>Var_TTR = new ArrayList<Double>();

public void failInfo(){
    BufferedReader buffer;
    try {
            buffer = new BufferedReader(new FileReader("C://Data/Australia/Information_for_Cloudsim.csv"));                     
            buffer.readLine(); //Skips the first line of the file. 
            String currentstr;
            while((currentstr=buffer.readLine()) != null){
                String[] column = currentstr.split(",");
                //System.out.println("column[0] = " +column[0]);

                if(column.length>0){
                    //hostID.add(Long.parseLong(column[0]));
                    hostID.add(Double.valueOf(column[0]).longValue());
                    MTBF.add(Double.parseDouble(column[1]));
                    SD_TBF.add(Double.parseDouble(column[2]));
                    Var_TBF.add(Double.parseDouble(column[3]));
                    MTTR.add(Double.parseDouble(column[4]));
                    SD_TTR.add(Double.parseDouble(column[5]));
                    Var_TTR.add(Double.parseDouble(column[6]));
                }               

            }
        }
         catch (IOException e) {
            e.printStackTrace();
            System.out.println("The simulation has been terminated due to an IO error");
        }   
    }



public static void main(String args[]){ 

GoogleFailureGenerator failgen = new GoogleFailureGenerator();

failgen.failInfo();

}
}

Any help will be highly appreciable.

Thanks in advance.

Yogesh Sharma

It seems pretty clear that your CSV is NOT in the format that you think it is. Look at it using Excel or a plain text editor. You should find a cell somewhere that says

    Preview truncated at 256 rows

instead of a valid number.

The most likely explanation is that the CSV file was not downloaded properly.

Your need to figure out why it didn't download properly; ie why you have a "preview" rather than a complete CSV. Then remedy that.


Hint: it pays to read the error messages ... in context. The actually error message says:

java.lang.NumberFormatException: 
    For input string: "Preview truncated at 256 rows" 

Notice that it says Number Format Exception, and that it is telling you exactly which string it thinks is not a correctly formatted number; ie the stuff inside the double quotes!!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM