我有一个逗号分隔的CSV文件,其中包含NASDAQ符号。我使用扫描仪读取文件
s = new Scanner(new File("C:\\nasdaq_companylist.csv")).useDelimiter("\\s*,\\s*");
我在第二个字段上遇到异常。问题是,该字段与文件中的其他某些字段一样也包含逗号,例如“ 1-800 FLOWERS.COM,Inc.”:
FLWS,"1-800 FLOWERS.COM, Inc.",2.8,76022800,n/a,1999,Consumer Services,Other Specialty Stores,http://www.nasdaq.com/symbol/flws
如何避免这个问题?我的代码是:
List theList = new ArrayList();
StringBuilder sb = new StringBuilder();
//get the title
String title = s.nextLine();
System.out.println("title: "+title);
while (s.hasNext())
{
String symbol = s.next();
String name = s.next();
double lastSale = s.nextDouble();
long marketCap = s.nextLong();
String adr =s.next();
String ipoYear=s.next();
String sector=s.next();
String industry = s.next();
String summaryQuote = s.next();
theList.add(newStock(symbol,lastSale));}
谢谢