本文整理汇总了Java中com.opencsv.CSVReader.readNext方法的典型用法代码示例。如果您正苦于以下问题:Java CSVReader.readNext方法的具体用法?Java CSVReader.readNext怎么用?Java CSVReader.readNext使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.opencsv.CSVReader
的用法示例。
在下文中一共展示了CSVReader.readNext方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: loadPageFromFile
import com.opencsv.CSVReader; //导入方法依赖的package包/类
public IPage loadPageFromFile(File file) {
try {
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(new FileInputStream(file), "UTF-8"));
CSVReader reader = new CSVReader(bufferedReader);
String[] firstLine = reader.readNext();
String pageName = firstLine[0];
String pageId = firstLine[2];
reader.readNext(); //skip line with column name
IPage result = new Page(pageName, pageId);
StreamSupport.stream(reader.spliterator(), false)
.map(cells -> getIElement(file, cells))
.forEach(result::addElement);
return result;
} catch (IOException e) {
throw new RuntimeException("Can't parse file " + file.getName(), e);
}
}
示例2: processSamples
import com.opencsv.CSVReader; //导入方法依赖的package包/类
private void processSamples() throws IOException {
for (int i = 0; i < SAMPLE_FILES.length; i++) {
String file = SAMPLE_FILES[i];
currentActivity = SAMPLE_CLASSIFIER[i].ordinal();
sampleCount = 0;
CSVReader reader = new CSVReader(new FileReader(SAMPLE_DIR + file));
String[] nextLine;
featureGenerator.reset();
while ((nextLine = reader.readNext()) != null) {
long ts = Long.parseLong(nextLine[0]);
float x = Float.parseFloat(nextLine[1]);
float y = Float.parseFloat(nextLine[2]);
float z = Float.parseFloat(nextLine[3]);
featureGenerator.addAccelerometerReading(ts, x, y, z);
}
}
}
示例3: readTestData
import com.opencsv.CSVReader; //导入方法依赖的package包/类
private static List<TrainingData> readTestData(String fn) {
int[] shape = { 3, 1 };
List<TrainingData> trainingDataSet = new ArrayList<>();
try {
CSVReader reader = new CSVReader(new FileReader(fn));
String[] row;
while ((row = reader.readNext()) != null) {
int type = Integer.parseInt(row[0]);
double f1 = Double.parseDouble(row[1]);
double f2 = Double.parseDouble(row[2]);
double f3 = Double.parseDouble(row[3]);
TrainingData trainingData = new TrainingData();
trainingData.input = Nd4j.create(new double[] { f1, f2, f3 }, shape);
trainingData.output = Nd4j.zeros(shape);
trainingData.output.putScalar(type, (double) 1);
trainingDataSet.add(trainingData);
}
} catch (java.io.IOException e) {
}
return trainingDataSet;
}
示例4: initColumns
import com.opencsv.CSVReader; //导入方法依赖的package包/类
private void initColumns() throws EmptyDataFileContentException, WrongDataFileFormatException, IOException {
columns = new ArrayList<>();
CSVReader reader = openInputData();
String[] headers = reader.readNext();
for (String header : headers) {
if (!"".equals(header)) {
columns.add(header);
}
}
reader.close();
if (columns.size() < 2) {
throw new EmptyDataFileContentException(Messages.getMessage(EmptyDataFileContentException.EMPTY_DATA_FILE_CONTENT_ERROR_MESSAGE));
}
resultColumnName = columns.get(columns.size() - 1);
if (!isResultColumnNameAuthorized(resultColumnName)) {
throw new WrongDataFileFormatException(String.format(Messages.getMessage(WrongDataFileFormatException.WRONG_RESULT_COLUMN_NAME_ERROR_MESSAGE), ResultColumnNames.getAuthorizedNames()));
}
}
示例5: RawTafFile
import com.opencsv.CSVReader; //导入方法依赖的package包/类
/**
* Parse d'un fichier Csv
* @param reader :CSVReader
* @throws IOException
*/
public RawTafFile(CSVReader reader) throws IOException {
logger.debug("IN");
String[] rawLine;
int i = 0;
int j = 0;
while ((rawLine = reader.readNext()) != null) {
List<String> parsedline = new ArrayList<String>();
for (String cell : rawLine) {
if(j == 0 && i != 0){//Première ligne
if(cell != null && !cell.equals("")){
columnsMap.put(i, cell);
}
}else if(i == 0 && j != 0){//Première colonne
if(cell != null && !cell.equals("")){
rowsMap.put(j, cell);
}
}
parsedline.add(cell == null ? "" : cell);
i++;
}
content.add(parsedline);
i=0;
j++;
}
}
示例6: ReadPasswordFile
import com.opencsv.CSVReader; //导入方法依赖的package包/类
private void ReadPasswordFile(String filepath) {
try {
CSVReader reader = new CSVReader(new FileReader(filepath));
String[] line;
while ((line = reader.readNext()) != null) {
if (line[VALIDPASSWORDCOLUMNINDEX].trim().length() != 0 && line[VALIDPASSWORDCOLUMNINDEX] != null) {
valid.add(line[VALIDPASSWORDCOLUMNINDEX]);
}
if (line[INVALIDPASSWORDCOLUMNINDEX].trim().length() != 0 && line[INVALIDPASSWORDCOLUMNINDEX] != null) {
invalid.add(line[INVALIDPASSWORDCOLUMNINDEX]);
}
}
} catch (IOException e) {
System.err.println("file not found");
}
}
示例7: ReadUserPassFile
import com.opencsv.CSVReader; //导入方法依赖的package包/类
private void ReadUserPassFile(String filepath){ //What is the format of the similarity file?
try {
CSVReader reader = new CSVReader(new FileReader(filepath));
String[] line;
while ((line = reader.readNext()) != null) {
usernamesim.add(line[USERNAMECOLUMNINDEX]);
passwordsim.add(line[PASSWORDCOLUMNINDEX]);
if(line[PASSWORDCOLUMNINDEX+1].trim().toLowerCase().equals("yes")) {
similarity.add(true);
}
else {
similarity.add(false);
}
}
} catch (IOException e) {
System.err.println("file not found");
}
}
示例8: doImport
import com.opencsv.CSVReader; //导入方法依赖的package包/类
/**
* Imports CSV files. Assumes the format of the file resembles:
* 42, 4, 5, 6
* 45, 6, 7, 8
* Where 42 and 45 are path ID's and (4,5,6) and (6,7,8) are node ID's along that path.
*
* @param csvFile
* @return The number of imported paths.
* @throws IOException
*/
public long doImport( File csvFile ) throws IOException
{
long importedPaths = 0;
CSVReader csvReader = new CSVReader( new FileReader( csvFile ) );
String[] line;
while ( (line = csvReader.readNext()) != null )
{
long pathId = Long.parseLong( line[0] );
List<Node> nodes = new ArrayList<>( line.length - 1 );
for ( int i = 1; i < line.length; i++ )
{
nodes.add( new Node( Long.parseLong( line[i] ) ) );
}
index.insert( ImmutablePath.builder().addAllNodes( nodes ).pathId( pathId ).build() );
importedPaths++;
}
return importedPaths;
}
示例9: readCsv
import com.opencsv.CSVReader; //导入方法依赖的package包/类
/**
* Reads the CSV file a returns the data inside the file
*
* @param context the app context
* @param csvFilePath the file to read
* @return the data from the CSV. The String[] contains follwoing information:
* 1. medicalId,
* 2. age,
* 3. gender,
* 4. RT timestamp,
* 5. Test Type e.g. pre-operation,
* 6. patients alertness,
* 7...n. reaction times
*/
public static final List<String[]> readCsv(Context context, String csvFilePath) {
List<String[]> questionList = new ArrayList<>();
AssetManager assetManager = context.getAssets();
try {
InputStream csvStream = assetManager.open(csvFilePath);
InputStreamReader csvStreamReader = new InputStreamReader(csvStream);
CSVReader csvReader = new CSVReader(csvStreamReader);
String[] line;
csvReader.readNext();
while ((line = csvReader.readNext()) != null) {
questionList.add(line);
}
} catch (Exception e) {
UtilsRG.error(e.getLocalizedMessage());
}
return questionList;
}
示例10: ExperienceTable
import com.opencsv.CSVReader; //导入方法依赖的package包/类
public ExperienceTable(FileHandle file) {
requiredExpGain = new ObjectMap<Integer, Integer>();
requiredExpTotal = new ObjectMap<Integer, Integer>();
CSVReader reader = new CSVReader(file.reader());
try {
String[] line = reader.readNext();
int total = 0;
for (int i = 0; i < line.length; ++i) {
int currGain = Integer.parseInt(line[i]);
requiredExpGain.put(i+2, currGain);
total += currGain;
requiredExpTotal.put(i+2, total);
}
} catch (IOException e) {
throw new GdxRuntimeException(e);
} finally {
StreamUtils.closeQuietly(reader);
}
}
示例11: getQuestionOptionIdRelationDBCsv
import com.opencsv.CSVReader; //导入方法依赖的package包/类
static HashMap<Long, Long> getQuestionOptionIdRelationDBCsv(Context context)
throws IOException {
HashMap<Long, Long> questionOptionFK = new HashMap<>();
List<QuestionOption> questionOptions = QuestionOption.listAll();
List<Long> csvIds = new ArrayList<>();
CSVReader reader = new CSVReader(
new InputStreamReader(context.openFileInput(PopulateDB.QUESTION_OPTIONS_CSV)),
PopulateDB.SEPARATOR, PopulateDB.QUOTECHAR);
String[] idToAdd;
while ((idToAdd = reader.readNext()) != null) {
csvIds.add(Long.parseLong(idToAdd[0]));
}
for (int i = 0; i < questionOptions.size() && i < csvIds.size(); i++) {
questionOptionFK.put(questionOptions.get(i).getId_question_option(), csvIds.get(i));
}
return questionOptionFK;
}
示例12: getOrganisationIdRelationCsvDB
import com.opencsv.CSVReader; //导入方法依赖的package包/类
static HashMap<Long, Partner> getOrganisationIdRelationCsvDB(Context context)
throws IOException {
HashMap<Long, Partner> organisationFK = new HashMap<>();
List<Partner> partners = Partner.getAllOrganisations();
List<Long> csvIds = new ArrayList<>();
CSVReader reader = new CSVReader(
new InputStreamReader(context.openFileInput(PopulateDB.PARTNER_CSV)),
PopulateDB.SEPARATOR, PopulateDB.QUOTECHAR);
String[] idToAdd;
while ((idToAdd = reader.readNext()) != null) {
csvIds.add(Long.parseLong(idToAdd[0]));
}
for (int i = 0; i < partners.size() && i < csvIds.size(); i++) {
organisationFK.put(csvIds.get(i), partners.get(i));
}
return organisationFK;
}
示例13: getAnswerFKRelationCsvDB
import com.opencsv.CSVReader; //导入方法依赖的package包/类
public static HashMap<Long, Answer> getAnswerFKRelationCsvDB(Context context)
throws IOException {
HashMap<Long, Answer> answerFK = new HashMap<>();
List<Answer> answers = Answer.getAllAnswers();
List<Long> csvIds = new ArrayList<>();
CSVReader reader = new CSVReader(
new InputStreamReader(context.openFileInput(PopulateDB.ANSWERS_CSV)),
PopulateDB.SEPARATOR, PopulateDB.QUOTECHAR);
String[] idToAdd;
while ((idToAdd = reader.readNext()) != null) {
csvIds.add(Long.parseLong(idToAdd[0]));
}
for (int i = 0; i < answers.size() && i < csvIds.size(); i++) {
answerFK.put(csvIds.get(i), answers.get(i));
}
return answerFK;
}
示例14: getOptionAttributeIdRelationCsvDB
import com.opencsv.CSVReader; //导入方法依赖的package包/类
public static HashMap<Long, OptionAttribute> getOptionAttributeIdRelationCsvDB(Context context)
throws IOException {
HashMap<Long, OptionAttribute> optionAttributeFK = new HashMap<>();
List<OptionAttribute> optionAttributes = OptionAttribute.getAllOptionAttributes();
List<Long> csvIds = new ArrayList<>();
CSVReader reader = new CSVReader(
new InputStreamReader(context.openFileInput(PopulateDB.OPTION_ATTRIBUTES_CSV)),
PopulateDB.SEPARATOR, PopulateDB.QUOTECHAR);
String[] idToAdd;
while ((idToAdd = reader.readNext()) != null) {
csvIds.add(Long.parseLong(idToAdd[0]));
}
for (int i = 0; i < optionAttributes.size() && i < csvIds.size(); i++) {
optionAttributeFK.put(csvIds.get(i), optionAttributes.get(i));
}
return optionAttributeFK;
}
示例15: getTabsIdRelationsCsvDB
import com.opencsv.CSVReader; //导入方法依赖的package包/类
static HashMap<Long, Tab> getTabsIdRelationsCsvDB(Context context)
throws IOException {
HashMap<Long, Tab> tabFK = new HashMap<>();
List<Tab> tabs = Tab.getAllTabs();
List<Long> csvIds = new ArrayList<>();
CSVReader reader = new CSVReader(
new InputStreamReader(context.openFileInput(PopulateDB.TABS_CSV)),
PopulateDB.SEPARATOR, PopulateDB.QUOTECHAR);
String[] idToAdd;
while ((idToAdd = reader.readNext()) != null) {
csvIds.add(Long.parseLong(idToAdd[0]));
}
for (int i = 0; i < tabs.size() && i < csvIds.size(); i++) {
tabFK.put(csvIds.get(i), tabs.get(i));
}
return tabFK;
}