将CSV文件导入ArrayList并在Java中转换值

时间:2017-04-30 15:49:36

标签: java csv arraylist

public static void main(String[] args) throws IOException
{
   String fileloc = "src\\assignment12\\Areas.csv";
   List<data> list = new ArrayList<data>();
    try {
       BufferedReader br = new BufferedReader(new FileReader(fileloc));
       String line = null;
       String read = br.readLine();
       while (read != null){

        String temp[] = read.split(",");  

        list.add(new data(temp[0], temp[1], temp[2], temp[3], temp[4]));

     System.out.println(list);
       }


       br.close();
   }catch (IOException e){
       System.out.println("Error Reading FIle");
   }
}

我的数据类

public class data extends States{
private String state;
private String total;
private String land;
private String water;
private String waterperc;

public data(String state, String total, String land, String water, String waterperc){



    this.state = state;
    this.total = total;
    this.land = land;
    this.water = water;
    this.waterperc = waterperc;
}

public String state(){
    return state;
}

public void getState(String state){
    this.state = state;
}

public String total(){
    return total;
}

public void getTotal(String total){
    this.total = total;
   }

public String land(){
    return land;
}

public void getLand(String land){
    this.land = land;
}
public String water(){
    return water;
}

public void getWater(String water){
    this.water = water;
}
public String waterperc(){
    return waterperc;
}

public void getWaterperc(String waterperc){
    this.waterperc = waterperc;
}
}

我很擅长编码所以请你好好哈哈!

当我尝试将数组从第二个转换为最后一个时,它不会让我将数据从String转换为double

我错过了什么,或者我只是完全不理解?

0 个答案:

没有答案