use of com.opencsv.CSVReader in project chuidiang-ejemplos by chuidiang.
the class MainWithOpenCsv method main.
public static void main(String[] args) {
CSVReader reader = null;
try {
reader = new CSVReader(new FileReader("files/Libro2.csv"), SEPARATOR, QUOTE);
String[] nextLine = null;
while ((nextLine = reader.readNext()) != null) {
System.out.println(Arrays.toString(nextLine));
}
} catch (Exception e) {
System.err.println("Error!! " + e.getMessage());
} finally {
if (null != reader) {
try {
reader.close();
} catch (IOException e) {
System.err.println("Error closing file!! " + e.getMessage());
}
}
}
}
use of com.opencsv.CSVReader in project airpal by airbnb.
the class ResultsPreviewResource method getFilePreview.
private Response getFilePreview(URI fileURI, int numLines) {
String fileName = getFilename(fileURI);
final File file = fileStore.get(fileName);
try {
if (file == null) {
throw new FileNotFoundException(fileName + " could not be found");
}
try (final CSVReader reader = new CSVReader(new FileReader(file))) {
return getPreviewFromCSV(reader, numLines);
} catch (IOException e) {
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
}
} catch (FileNotFoundException e) {
log.warn(e.getMessage());
return Response.status(Response.Status.NOT_FOUND).build();
}
}
use of com.opencsv.CSVReader in project perun by CESNET.
the class ExtSourceCSV method csvParsing.
private List<Map<String, String>> csvParsing(String query, int maxResults) throws InternalErrorException, FileNotFoundException, IOException {
List<Map<String, String>> subjects = new ArrayList<Map<String, String>>();
FileReader fileReader = new FileReader(file);
if (fileReader == null) {
throw new FileNotFoundException("File was not found!");
}
CSVReader reader = new CSVReader(fileReader);
header = reader.readNext();
if (header == null) {
throw new RuntimeException("No header in csv file");
}
String[] row;
while ((row = reader.readNext()) != null) {
if (header.length != row.length) {
throw new RuntimeException("Csv file is not valid - some rows have different number of columns from the header row.");
}
if (compareRowToQuery(row, query)) {
Map<String, String> map = convertLineToMap(row);
if (map != null) {
subjects.add(map);
}
if (maxResults > 0) {
if (subjects.size() >= maxResults) {
break;
}
}
}
}
return subjects;
}
use of com.opencsv.CSVReader in project pictureapp by EyeSeeTea.
the class PopulateDB method addVisibleQuestions.
public static void addVisibleQuestions(Context context, List<Question> questions) throws IOException {
//Reset inner references
CSVReader reader = new CSVReader(new InputStreamReader(context.openFileInput(QUESTIONS_CSV)), SEPARATOR, QUOTECHAR);
String[] line;
while ((line = reader.readNext()) != null) {
for (Question question : questions) {
if (question.getUid().equals(line[5])) {
question.setVisible(Integer.valueOf(line[14]));
question.save();
break;
}
}
}
reader.close();
}
use of com.opencsv.CSVReader in project pictureapp by EyeSeeTea.
the class PopulateDB method addTotalQuestions.
public static void addTotalQuestions(Context context, List<Question> questions) throws IOException {
//Reset inner references
CSVReader reader = new CSVReader(new InputStreamReader(context.openFileInput(QUESTIONS_CSV)), SEPARATOR, QUOTECHAR);
String[] line;
while ((line = reader.readNext()) != null) {
for (Question question : questions) {
if (question.getUid().equals(line[5])) {
question.setTotalQuestions(Integer.valueOf(line[13]));
question.save();
break;
}
}
}
reader.close();
}
Aggregations