本文整理汇总了Java中com.csvreader.CsvReader.setHeaders方法的典型用法代码示例。如果您正苦于以下问题:Java CsvReader.setHeaders方法的具体用法?Java CsvReader.setHeaders怎么用?Java CsvReader.setHeaders使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.csvreader.CsvReader
的用法示例。
在下文中一共展示了CsvReader.setHeaders方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: test70
import com.csvreader.CsvReader; //导入方法依赖的package包/类
@Test
public void test70() throws Exception {
String data = "\"1\",Bruce\r\n\"2\",Toni\r\n\"3\",Brian\r\n";
CsvReader reader = CsvReader.parse(data);
reader.setHeaders(new String[] { "userid", "name" });
Assert.assertEquals(2, reader.getHeaderCount());
Assert.assertTrue(reader.readRecord());
Assert.assertEquals("1", reader.get("userid"));
Assert.assertEquals("Bruce", reader.get("name"));
Assert.assertEquals(0L, reader.getCurrentRecord());
Assert.assertEquals(2, reader.getColumnCount());
Assert.assertTrue(reader.readRecord());
Assert.assertEquals("2", reader.get("userid"));
Assert.assertEquals("Toni", reader.get("name"));
Assert.assertEquals(1L, reader.getCurrentRecord());
Assert.assertEquals(2, reader.getColumnCount());
Assert.assertTrue(reader.readRecord());
Assert.assertEquals("3", reader.get("userid"));
Assert.assertEquals("Brian", reader.get("name"));
Assert.assertEquals(2L, reader.getCurrentRecord());
Assert.assertEquals(2, reader.getColumnCount());
Assert.assertFalse(reader.readRecord());
reader.close();
}
示例2: test76
import com.csvreader.CsvReader; //导入方法依赖的package包/类
@Test
public void test76() throws Exception {
CsvReader reader = CsvReader.parse("user_id,name\r\n1,Bruce");
Assert.assertNull(reader.getHeaders());
Assert.assertEquals(-1, reader.getIndex("user_id"));
Assert.assertEquals("", reader.getHeader(0));
Assert.assertTrue(reader.readHeaders());
Assert.assertEquals(0, reader.getIndex("user_id"));
Assert.assertEquals("user_id", reader.getHeader(0));
String[] headers = reader.getHeaders();
Assert.assertEquals(2, headers.length);
Assert.assertEquals("user_id", headers[0]);
Assert.assertEquals("name", headers[1]);
reader.setHeaders(null);
Assert.assertNull(reader.getHeaders());
Assert.assertEquals(-1, reader.getIndex("user_id"));
Assert.assertEquals("", reader.getHeader(0));
reader.close();
}