开发者社区> 问答> 正文

从CSV文件读取第一个元素时出错

我正在尝试使用rectangle.csvJava 读取文件。但是,当我读取文件并分配给字符串数组时,第一个元素与第一个元素一起读取了一些垃圾值。

package sample;

import java.io.BufferedReader; import java.io.FileReader; import java.time.LocalDateTime;

public class rectangleDemo { private static Rectangle[] rect ; private static int count; static private void loadFile( String filepath) { try { // Try catch expression to catch exception String info=" "; BufferedReader reader =null;
reader = new BufferedReader(new FileReader(filepath));

        while ((info = reader.readLine()) != null) 
        {
             String temp[] = info.split(",");
           //
          System.out.println(temp[0]);
          System.out.println(temp[1]);    
    }
        System.out.println("Database loaded successfully!");
        reader.close();
    }
    catch (Exception e) 
    {
        e.printStackTrace(System.out);
    }
} 

public static void main(String[] args) { // TODO Auto-generated method stub loadFile("rectangle.txt"); }

展开
收起
小六码奴 2019-10-17 16:54:02 6100 0
1 条回答
写回答
取消 提交回答
  • 精于基础,广于工具,熟于业务。

    第一行为啥报错呢?是不是分隔符不对

    2019-10-17 17:07:43
    赞同 展开评论 打赏
问答地址:
问答排行榜
最热
最新

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载