当前位置 : 主页 > 网络编程 > 其它编程 >

java给hashmap添加键值对_在JAVA中将CSV值转换为HashMap键值对

来源:互联网 收集:自由互联 发布时间:2023-07-02
嗨我有一个csv叫做test.csv。我试图逐行读取csv并将值转换为哈希键值对。这是代码-publicclassExample{publicsta 嗨我有一个csv叫做test.csv。我试图逐行读取csv并将值转换为哈希键值对。这是代码
嗨我有一个csv叫做test.csv。我试图逐行读取csv并将值转换为哈希键值对。这是代码-publicclassExample{publicsta

嗨我有一个csv叫做test.csv。我试图逐行读取csv并将值转换为哈希键值对。这是代码-

public class Example {

public static void main(String[] args) throws ParseException, IOException {

// TODO Auto-generated method stub

BufferedReader br new BufferedReader(new FileReader("test.csv"));

String line null;

HashMap map new HashMap();

while((linebr.readLine())!null){

String str[] line.split(",");

for(int i0;i

String arr[] str[i].split(":");

map.put(arr[0], arr[1]);

}

}

System.out.println(map);

}

}

csv文件如下-

1,"testCaseName":"ACLTest","group":"All_Int","projectType":"GEN","vtName":"NEW_VT","status":"ACTIVE","canOrder":"Yes","expectedResult":"duplicateacltrue"

2,"testCaseName":"DCLAddTest","group":"India_Int","projectType":"GEN_NEW","vtName":"OLD_VT","status":"ACTIVE","canOrder":"Yes","expectedResult":"invalidfeaturesacltrue"

当我运行此代码时出现此错误-

Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 1

Example.main(Example.java:33)

谁能帮助我修复代码并找出程序中的错误

【感谢龙石为本站提供数据共享交换平台 http://www.longshidata.com/pages/exchange.html】
上一篇:WordPress加速及性能优化–隐藏WordPress版本
下一篇:没有了
网友评论