int indexYear = 0;
int indexMonth = 0;
int indexDay = 0;
int indexFirstname = 0;
int indexSecondname = 0;
String strForFirstLine="";
strForFirstLine += input.readLine();
String getFirstLine[] = strForFirstLine.split(",");
for(int i=0; i<getFirstLine.length; ++i){
if(getFirstLine[i].equals("'Year'"))
indexYear = i;
if(getFirstLine[i].equals("'Month'"))
indexMonth = i;
if(getFirstLine[i].equals("'Day'"))
indexDay = i;
if(getFirstLine[i].equals("'Firstname'"))
indexFirstName = i;
if(getFirstLine[i].equals("'Secondname'"))
indexSecondName = i;
}
提前致谢:)。
从arrayList获取SecondName的输出:
The output for getting the firstName: 'code' run:
&#34;3分之2012&#34; &#34;3分之2012&#34; &#34;3分之2012&#34; &#34;3分之2012&#34; &#34;3分之2012&#34; &#34;3分之2012&#34; &#34;3分之2012&#34; &#34;3分之2012&#34; &#34;3分之2012&#34; &#34;3分之2012&#34; &#34;3分之2012&#34; &#34;3分之2012&#34; &#34;3分之2012&#34; &#34;3分之2012&#34; &#34;3分之2012&#34; &#34;3分之2012&#34; &#34;3分之2012&#34; &#34;3分之2012&#34; &#34;3分之2012&#34; &#34;3分之2012&#34; &#34;3分之2012&#34; &#34;3分之2012&#34; &#34;3分之2012&#34; &#34;3分之2012&#34; &#34;3分之2012&#34; &#34;3分之2012&#34; &#34;3分之2012&#34; &#34;3分之2012&#34; &#34;3分之2012&#34; &#34;3分之2012&#34; &#34;3分之2012&#34; &#34;3分之2012&#34; &#34;3分之2012&#34; &#34;3分之2012&#34; &#34;3分之2012&#34; &#34;3分之2012&#34; &#34;3分之2012&#34; &#34;3分之2012&#34; &#34;3分之2012&#34; &#34;3分之2012&#34; &#34;3分之2012&#34; &#34;3分之2012&#34; &#34;3分之2012&#34; &#34;3分之2012&#34; &#34;3分之2012&#34; &#34;3分之2012&#34; &#34;3分之2012&#34; &#34;3分之2012&#34; &#34;3分之2012&#34; &#34;3分之2012&#34; &#34;3分之2012&#34; &#34;3分之2012&#34; &#34;3分之2012&#34; &#34;3分之2012&#34; &#34;3分之2012&#34; &#34;3分之2012&#34; &#34;3分之2012&#34; &#34;3分之2012&#34; &#34;3分之2012&#34; &#34;3分之2012&#34; &#34;3分之2012&#34; &#34;3分之2012&#34; &#34;3分之2012&#34; &#34;3分之2012&#34; &#34;3分之2012&#34; &#34;3分之2012&#34; &#34;3分之2012&#34; &#34;3分之2012&#34; &#34;3分之2012&#34; &#34;3分之2012&#34; &#34;3分之2012&#34; &#34;3分之2012&#34; &#34;3分之2012&#34; &#34;3分之2012&#34; 空值 建立成功(总时间:0秒)
答案 0 :(得分:2)
尝试CSVReader Api,这会让您的生活更轻松
实施例
CsvReader products = new CsvReader("products.csv");
products.readHeaders();
while (products.readRecord())
{
String productID = products.get("ProductID");
String productName = products.get("ProductName");
String supplierID = products.get("SupplierID");
String categoryID = products.get("CategoryID");
String quantityPerUnit = products.get("QuantityPerUnit");
String unitPrice = products.get("UnitPrice");
String unitsInStock = products.get("UnitsInStock");
String unitsOnOrder = products.get("UnitsOnOrder");
String reorderLevel = products.get("ReorderLevel");
String discontinued = products.get("Discontinued");
// perform program logic here
System.out.println(productID + ":" + productName);
}
products.close();
然后在ArrayList
中添加要添加的内容答案 1 :(得分:0)
使用uniVocity-parsers CsvParser:
CsvParserSettings settings = new CsvParserSettings();
//defines the order of the fields you are interested in reading.
parserSettings.selectFields("ProductID", "ProductName", etc...);
CsvParser parser = new CsvParser(settings);
//returns the rows at the specified order
List<String[]> rows = parser.parseAll(new FileReader("your_input_file"));
如何订购每个CSV输入的标题并不重要。解析器将从输入中获取正确的值。如果CSV没有您选择的标题,则返回null。
查看文档,有很多选项可以帮助您处理各种野生输入。
披露:我是这个图书馆的作者。它是开源和免费的(Apache V2.0许可证)。