我是 java 菜鸟。我有一个csv文件,里面有六行。我读所有的行没有问题,但是如果我只想读一行,例如第3行。我怎么能这么做?然后也能读取特定列中的特定细胞。
代码:
import com.opencsv.CSVReader;
import java.io.FileReader;
import java.util.Arrays;
import java.util.List;
public class ParseFullCSVExample
{
public static void main(String[] args) throws Exception
{
//Build reader instance
CSVReader reader = new CSVReader(new FileReader("6rows.csv"));
//Read all rows at once
List<String[]> allRows = reader.readAll();
//Read CSV line by line and use the string array as you want
for(String[] row : allRows){
System.out.println(Arrays.toString(row));
}
}
}
完整输出:
[TestId, TestName, TestModule, TestType, TestSteps, Action, TestResult, Note]
[1234, Login, Dashboard, Regression, 1, Open Browser, , ]
[1234, Login, Dashboard, Regression, 2, Enter user name, , ]
[1234, Login, Dashboard, Regression, 3, Enter user password, , ]
[1234, Login, Dashboard, Regression, 4, Click on login button, , ]
[1234, Login, Dashboard, Regression, 5, Verify that Logout link should be displayed, , ]
我要实现的输出(行3/cell3):
[ Dashboard ]
暂无答案!
目前还没有任何答案,快来回答吧!