我将从第三方获取以下csv文件
从这个CSV文件我想从下面提取名称
(VEDL,RELIANCE,塔塔汽车,NTPC,MARUTI)
,Top Five Nifty 50 Gainers:
,SYMBOL,SERIES,CLOSE PRICE,PREV.CLOSE,%CHANGE
,VEDL,EQ, 85.00, 81.05,4.87
,RELIANCE,EQ, 1051.60, 1025.75,2.52
,TATAMOTORS,EQ, 360.20, 353.35,1.94
,NTPC,EQ, 141.60, 139.55,1.47
,MARUTI,EQ, 4272.40, 4214.75,1.37
这是我的程序,我作为参考。
package com.util;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.PipedReader;
import java.io.PipedWriter;
import au.com.bytecode.opencsv.CSVReader;
public class TestProgram {
public static void main(String args[]) {
final String startToken = ",Nifty 50 Gainers";
final String endToken = "50 Losers";
final PipedWriter pipedWriter = new PipedWriter();
PipedReader pipedReaderTmp = null;
try {
pipedReaderTmp = new PipedReader(pipedWriter);
} catch (IOException e) {
}
final PipedReader pipedReader = pipedReaderTmp;
// Consumer
new Thread(new Runnable() {
@Override
public void run() {
try {
CSVReader csvReader = new CSVReader(pipedReader);
while (true) {
String[] line = csvReader.readNext(); // blocks until the next line is available
if (line == null)
break; // end of stream has been reached
if (line != null && line.length > 3) {
String indices_name = line[1];
if (indices_name != null) {
System.out.println(indices_name);
}
}
}
} catch (IOException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
}
}).start();
// Producer
new Thread(new Runnable() {
@Override
public void run() {
try {
BufferedReader br = new BufferedReader(new FileReader(
"C:\\Users\\ravikiranv\\Downloads\\MA050116.csv"));
String line = null;
while ((line = br.readLine()) != null) {
if (startToken.equals(line))
break;
}
while ((line = br.readLine()) != null) {
if (line.contains((endToken))) {
break;
} else {
pipedWriter.write(line + '\n');
}
}
pipedWriter.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}).start();
}
}
但是当我运行该程序时,我在pipedWriter中没有得到任何东西
整个csv文件都是这样的
,11-Jan-2016
The Nifty witnessed an intraday movement of about 110.75 points.The closing index was 0.49 % down as compared to the previous closing index.
, Traded Value (Rs. In Crores), 16359.76
, Traded Quantity (in Lakhs), 10682.44
, Number of Trades, 7547729
, Total Market Capitalisation (Rs. Crores), 9491205.95
,INDEX,PREVIOUS CLOSE,OPEN,HIGH,LOW,CLOSE,GAIN/LOSS
,Nifty 50, 7601.35, 7527.45, 7605.10, 7494.35, 7563.85,-37.5
,Nifty IT, 10989.55, 10898.80, 10917.45, 10797.70, 10823.90,-165.65
,Nifty Next 50, 19598.75, 19483.55, 19530.85, 19275.80, 19379.80,-218.95
,Nifty Bank, 16142.65, 15979.05, 16156.80, 15840.60, 16016.25,-126.4
,ADVANCES,578
,DECLINES,994
,UNCHANGED,61
,Total securities that have hit their price bands today,152
,TOP 25 Securities Today :
,SYMBOL,SERIES,PREV. CLOSE,CLOSE PRICE,%VAR, VALUE(Rs Crs)
,RELIANCE,EQ, 1025.75, 1051.60,2.52,695.04
,AXISBANK,EQ, 413.70, 417.20,0.85,431.92
,SBIN,EQ, 208.95, 204.30,-2.23,394.82
,Top Five Nifty 50 Gainers:
,SYMBOL,SERIES,CLOSE PRICE,PREV.CLOSE,%CHANGE
,VEDL,EQ, 85.00, 81.05,4.87
,RELIANCE,EQ, 1051.60, 1025.75,2.52
,TATAMOTORS,EQ, 360.20, 353.35,1.94
,NTPC,EQ, 141.60, 139.55,1.47
,MARUTI,EQ, 4272.40, 4214.75,1.37
,Top Five Nifty 50 Losers:
,SYMBOL,SERIES,CLOSE PRICE,PREV.CLOSE,%CHANGE
,WIPRO,EQ, 537.45, 555.80,-3.3
,ADANIPORTS,EQ, 234.05, 241.40,-3.04
,M&M,EQ, 1162.60, 1198.00,-2.95
,TECHM,EQ, 507.30, 522.15,-2.84
,BHEL,EQ, 149.45, 153.60,-2.7
,Securities Price Volume Data in Normal market
,SYMBOL,SERIES,CLOSE PRICE,TRADED VALUE ,TRADED QUANTITY
,20MICRONS,EQ, 36.55, 4494342.20,123972
,3IINFOTECH,EQ, 5.65, 34819990.20,6217017
,3MINDIA,EQ, 10653.95, 3626784.60,341
,8KMILES,EQ, 2356.70, 259881198.20,109041
,A2ZINFRA,EQ, 26.65, 3515954.10,131509
,AARTIDRUGS,EQ, 560.00, 15268435.55,27246
,AARTIIND,EQ, 508.80, 8941675.40,17568
,AARVEEDEN,EQ, 63.75, 174019.55,2769
请您告诉我如何在文本
之后解析这五个符号及其数据前五名娴熟的50名获胜者: