本文整理了Java中au.com.bytecode.opencsv.CSVReader.<init>()
方法的一些代码示例,展示了CSVReader.<init>()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。CSVReader.<init>()
方法的具体详情如下:
包路径:au.com.bytecode.opencsv.CSVReader
类名称:CSVReader
方法名:<init>
[英]Constructs CSVReader using a comma for the separator.
[中]使用逗号作为分隔符构造CSVReader。
代码示例来源:origin: databricks/learning-spark
public Tuple2<Integer, String[]> call(String line) throws Exception {
CSVReader reader = new CSVReader(new StringReader(line));
String[] elements = reader.readNext();
Integer key = Integer.parseInt(elements[0]);
return new Tuple2(key, elements);
}
}
代码示例来源:origin: stackoverflow.com
CSVReader reader = new CSVReader(new FileReader(file), ',', '\'', 1);
代码示例来源:origin: stackoverflow.com
public class ParseCSV {
public static void main(String[] args) {
try {
//csv file containing data
String strFile = "C:\\Users\\rsaluja\\CMS_Evaluation\\Drupal_12_08_27.csv";
CSVReader reader = new CSVReader(new FileReader(strFile));
String [] nextLine;
int lineNumber = 0;
while ((nextLine = reader.readNext()) != null) {
lineNumber++;
System.out.println("Line # " + lineNumber);
// nextLine[] is an array of values from the line
System.out.println(nextLine[4] + "etc...");
}
}
}
}
代码示例来源:origin: stackoverflow.com
import java.io.*;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.*;
import au.com.bytecode.opencsv.CSVReader;
class Test {
public static void main(String[] args) throws IOException {
Workbook wb = new HSSFWorkbook();
CreationHelper helper = wb.getCreationHelper();
Sheet sheet = wb.createSheet("new sheet");
CSVReader reader = new CSVReader(new FileReader("data.csv"));
String[] line;
int r = 0;
while ((line = reader.readNext()) != null) {
Row row = sheet.createRow((short) r++);
for (int i = 0; i < line.length; i++)
row.createCell(i)
.setCellValue(helper.createRichTextString(line[i]));
}
// Write the output to a file
FileOutputStream fileOut = new FileOutputStream("workbook.xls");
wb.write(fileOut);
fileOut.close();
}
}
代码示例来源:origin: forcedotcom/phoenix
/**
* Upserts data from CSV file. Data is batched up based on connection batch
* size. Column PDataType is read from metadata and is used to convert
* column value to correct type before upsert. Note: Column Names are
* expected as first line of CSV file.
*
* @param fileName
* @throws Exception
*/
public void upsert(String fileName) throws Exception {
List<String> delimiter = this.delimiter;
CSVReader reader;
if ((delimiter != null) && (delimiter.size() == 3)) {
reader = new CSVReader(new FileReader(fileName),
getCSVCustomField(this.delimiter.get(0)),
getCSVCustomField(this.delimiter.get(1)),
getCSVCustomField(this.delimiter.get(2)));
} else {
reader = new CSVReader(new FileReader(fileName));
}
upsert(reader);
}
代码示例来源:origin: stackoverflow.com
FileInputStream fis = new FileInputStream("awesomefile.csv");
InputStreamReader isr = new InputStreamReader(fis, "UTF-8");
CSVReader reader = new CSVReader(isr);
for (String[] row; (row = reader.readNext()) != null;) {
System.out.println(Arrays.toString(row));
}
reader.close();
isr.close();
fis.close();
代码示例来源:origin: stackoverflow.com
CSVReader reader = new CSVReader(new FileReader("yourfile.csv"));
String [] nextLine;
while ((nextLine = reader.readNext()) != null) {
// nextLine[] is an array of values from the line
System.out.println(nextLine[0] + nextLine[1] + "etc...");
}
代码示例来源:origin: stackoverflow.com
try {
CSVReader reader = new CSVReader(new FileReader(file.getAbsolutePath()));
}catch(FileNotFoundException fnfe) {
// handle exception, e.g. show error message
}
代码示例来源:origin: stackoverflow.com
CSVReader reader=new CSVReader(
new InputStreamReader(new FileInputStream("d:\\a.csv"), "UTF-8"),
',', '\'', 1);
String[] line;
while ((line = reader.readNext()) != null) {
StringBuilder stb = new StringBuilder(400);
for (int i = 0; i < line.length; i++) {
stb.append(line[i]);
stb.append(";");
}
System.out.println(stb);
}
代码示例来源:origin: stackoverflow.com
CSVReader reader = new CSVReader(new FileReader("C:/Users/Thanushiya/Desktop/mobios/internship/csvfile/csvfile/Master.csv"), ',', '\'', 17);
String [] nextLine;
while ((nextLine = reader.readNext()) != null) {
// put the code from your for loop here
}
代码示例来源:origin: stackoverflow.com
for (int j = 0; j < fileList.size(); j++) {
String csvFile = readPath + fileList.get(j);
System.out.println("Read: " + csvFile);
reader = new CSVReader(new FileReader(csvFile), ';');
hugeList = reader.readAll();
String[] data = new String[1];
for (int m = 0; m < hugeList.size(); m++) {
String[] values = hugeList.get(m);
data[0] = values[0];
writer.writeNext(data);
}
}
代码示例来源:origin: stackoverflow.com
String next[] = {};
List<String[]> list = new ArrayList<String[]>();
try {
CSVReader reader = new CSVReader(new InputStreamReader(getAssets().open("test.csv")));
while(true) {
next = reader.readNext();
if(next != null) {
list.add(next);
} else {
break;
}
}
} catch (IOException e) {
e.printStackTrace();
}
代码示例来源:origin: stackoverflow.com
CSVReader reader = new CSVReader(new FileReader("yourfile.csv"), '|');
String [] nextLine;
while ((nextLine = reader.readNext()) != null)
{
// nextLine[] is an array of values from the line
if(nextLine[0] == desiredBookName)
{
// Output desired attributes
}
}
代码示例来源:origin: stackoverflow.com
for (int j = 0; j < fileList.size(); j++) {
String csvFile = readPath + fileList.get(j);
System.out.println("Read: " + csvFile);
reader = new CSVReader(new FileReader(csvFile), ';');
hugeList = reader.readAll();
String[] data = new String[1];
for (int m = 0; m < hugeList.size(); m++) {
String[] values = hugeList.get(m);
data[0] = values[0];
writer.writeNext(data);
}
}
代码示例来源:origin: Graylog2/graylog2-server
final ImmutableMap.Builder<String, String> newLookupBuilder = ImmutableMap.builder();
try (final CSVReader csvReader = new CSVReader(fileReader, config.separatorAsChar(), config.quotecharAsChar())) {
int line = 0;
int keyColumn = -1;
final String[] next = csvReader.readNext();
if (next == null) {
break;
代码示例来源:origin: stackoverflow.com
CSVReader rec = new CSVReader(new FileReader(filePath));
String[] recLine;
while ((recLine = rec.readNext()) != null) {
//Get the data from recLine
}
代码示例来源:origin: stackoverflow.com
// Read all
CSVReader csvReader = new CSVReader(new FileReader(new File("nrldata.txt")));
List<String[]> list = csvReader.readAll();
// Convert to 2D array
String[][] dataArr = new String[list.size()][];
dataArr = list.toArray(dataArr);
代码示例来源:origin: nodebox/nodebox
Character quot = separators.get(quotationCharacter);
if (quot == null) quot = '"';
CSVReader reader = new CSVReader(in, sep, quot);
ImmutableList.Builder<Map<String, Object>> b = ImmutableList.builder();
String[] headers = reader.readNext();
while ((row = reader.readNext()) != null) {
ImmutableMap.Builder<String, Object> mb = ImmutableMap.builder();
for (int i = 0; i < row.length; i++) {
代码示例来源:origin: stackoverflow.com
CSVReader reader = new CSVReader(new FileReader(fileToParse));
String[] recordArray = null;
while ((recordArray = reader.readNext()) != null) {
// use recordArray...
}
代码示例来源:origin: stackoverflow.com
CSVReader reader1 = new CSVReader(new FileReader(mydata_csv.getpath()));
List<String[]> myDatas = reader1.readAll();
String[] lineI = myDatas.get(i);
for (String[] line : myDatas) {
for (String value : line) {
//do stuff with value
}
}
内容来源于网络,如有侵权,请联系作者删除!