本文整理匯總了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();
}