[英]how to read .csv file as key value pair?
username 1 abc
password 1 123
username 2 pqr
password 2 456
username 3 xyz
password 3 789
how to read .csv file
values like .properties file
, means whenever we give key name its should display value correspondence to that key in selenium? 如何读取.csv file
值(如.properties file
,意味着每当我们给键名命名时,它应该显示与硒中该键的值对应?
when I enter username1 it should display abc
. 当我输入username1 it should display abc
。 similarly,s for password1 it should display 123 in java 类似地,对于password1,s应该在Java中显示123
Assuming Your CSV file is structured as -> 假设您的CSV文件的结构为->
username 1, abc
password 1, 123
username 2, pqr
password 2, 456
username 3, xyz
password 3, 789
Use the following -> 使用以下->
BufferedReader br = new BufferedReader(new FileReader(new File("test.csv")));
String str="";
Map<String,String> map = new HashMap<String,String>();
while((str=br.readLine())!=null)
{
map.put(str.split(",")[0],str.split(",")[1]);
}
This should give you the output. 这应该给您输出。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.