本文整理汇总了Java中com.opencsv.CSVWriter.close方法的典型用法代码示例。如果您正苦于以下问题:Java CSVWriter.close方法的具体用法?Java CSVWriter.close怎么用?Java CSVWriter.close使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.opencsv.CSVWriter
的用法示例。
在下文中一共展示了CSVWriter.close方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: build
import com.opencsv.CSVWriter; //导入方法依赖的package包/类
public static File build(Long examId, Collection<Long> childIds) throws IOException {
List<ExamRecord> examRecords = Ebean.find(ExamRecord.class)
.fetch("examScore")
.where()
.eq("exam.parent.id", examId)
.in("exam.id", childIds)
.findList();
File file = File.createTempFile("csv-output-", ".tmp");
CSVWriter writer = new CSVWriter(new FileWriter(file));
writer.writeNext(ExamScore.getHeaders());
for (ExamRecord record : examRecords) {
writer.writeNext(record.getExamScore().asArray(record.getStudent(), record.getTeacher(), record.getExam()));
}
writer.close();
return file;
}
示例2: writeStopTimes
import com.opencsv.CSVWriter; //导入方法依赖的package包/类
/**
* Experimental class to write stop_times.txt from a (filtered) collection of trips. stop_times.txt is
* usually the largest file.
*/
public static void writeStopTimes(Collection<Trip> trips, String folder) throws IOException {
CSVWriter stopTimesWriter = new CSVWriter(new FileWriter(folder + GtfsDefinitions.Files.STOP_TIMES.fileName), ',');
String[] header = GtfsDefinitions.Files.STOP_TIMES.columns;
stopTimesWriter.writeNext(header, true);
for(Trip trip : trips) {
for(StopTime stopTime : trip.getStopTimes()) {
// TRIP_ID, STOP_SEQUENCE, ARRIVAL_TIME, DEPARTURE_TIME, STOP_ID
String[] line = new String[header.length];
line[0] = stopTime.getTrip().getId();
line[1] = String.valueOf(stopTime.getSequencePosition());
line[2] = Time.writeTime(stopTime.getArrivalTime());
line[3] = Time.writeTime(stopTime.getDepartureTime());
line[4] = stopTime.getStop().getId();
stopTimesWriter.writeNext(line);
}
}
stopTimesWriter.close();
}
示例3: merge
import com.opencsv.CSVWriter; //导入方法依赖的package包/类
private synchronized void merge(List<File> inputFiles, File outputFile) throws IOException {
AttributeSetCollector collector = null;
CSVWriter writer = null;
try {
collector = new AttributeSetCollector(inputFiles);
writer = FileUtil.createWriter(outputFile);
while (collector.hasNext()) {
String[] nextList = collector.nextValue2AttSet();
writer.writeNext(nextList);
}
} finally {
if (collector != null) {
collector.close();
}
if (writer != null) {
writer.close();
}
}
}
示例4: writeStops
import com.opencsv.CSVWriter; //导入方法依赖的package包/类
/**
* Experimental class to write stops.txt (i.e. after filtering for one date)
*/
public static void writeStops(Collection<Stop> stops, String folder) throws IOException {
CSVWriter stopsWriter = new CSVWriter(new FileWriter(folder + GtfsDefinitions.Files.STOPS.fileName), ',');
String[] header = GtfsDefinitions.Files.STOPS.columns;
stopsWriter.writeNext(header, true);
for(Stop stop : stops) {
// STOP_ID, STOP_LON, STOP_LAT, STOP_NAME
String[] line = new String[header.length];
line[0] = stop.getId();
line[1] = String.valueOf(stop.getLon());
line[2] = String.valueOf(stop.getLat());
line[3] = stop.getName();
stopsWriter.writeNext(line);
}
stopsWriter.close();
}
示例5: processCsv
import com.opencsv.CSVWriter; //导入方法依赖的package包/类
private String processCsv(TableModel model, Writer dest) throws IOException {
CSVWriter writer = new CSVWriter(dest, DELIMITER, QUOTE);
try {
String[] row = new String[model.getColumnCount()];
for (int j = 0; j < model.getColumnCount(); j++)
row[j] = model.getColumnName(j);
writer.writeNext(row);
for (int i = 0; i < model.getRowCount(); i++) {
for (int j = 0; j < model.getColumnCount(); j++)
row[j] = (String) model.getValueAt(i, j);
writer.writeNext(row);
}
writer.flush();
return (String.format("Exported %d rows", model.getRowCount()));
} finally {
writer.close();
}
}
示例6: exportTrajectoryDataAsCSV
import com.opencsv.CSVWriter; //导入方法依赖的package包/类
public void exportTrajectoryDataAsCSV(ArrayList<? extends Trajectory> tracks, String path){
String[] nextLine = null;
try {
CSVWriter writer = new CSVWriter(new FileWriter(path, false), ',');
nextLine = new String[]{"ID","X","Y","CLASS"};
writer.writeNext(nextLine);
for(int i = 0; i < tracks.size(); i++){
Trajectory t = tracks.get(i);
for(int j = 0; j < t.size(); j++){
nextLine = new String[]{""+t.getID(),""+t.get(j).x,""+t.get(j).y,t.getType()};
writer.writeNext(nextLine);
}
}
writer.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
示例7: saveProductsToCsv
import com.opencsv.CSVWriter; //导入方法依赖的package包/类
public static void saveProductsToCsv(HashMap<String, List<String>> cache) {
try {
File file = new File(CSV_PATH);
if (!file.exists()) {
file.getParentFile().mkdirs();
file.createNewFile();
}
CSVWriter csvWriter = new CSVWriter(new FileWriter(CSV_PATH));
for (Map.Entry<String, List<String>> entry : cache.entrySet()) {
String key = entry.getKey();
for (String item : entry.getValue()) {
csvWriter.writeNext(new String[]{key, item});
}
}
csvWriter.close();
} catch (IOException e) {
e.printStackTrace();
}
}
示例8: writeCSVFile
import com.opencsv.CSVWriter; //导入方法依赖的package包/类
public XmlDocMaker writeCSVFile(Collection<Element> elements,
char delimiter, boolean xpathOutput, Collection<String> xpaths,
Outputs out) throws Throwable {
XmlDocMaker doc = new XmlDocMaker("nbResults");
File of = PluginService.createTemporaryFile();
CSVWriter csvWriter = new CSVWriter(new OutputStreamWriter(
new BufferedOutputStream(new FileOutputStream(of, true))),
delimiter, '"');
int count = 0;
Collection<String[]> table = createContentTable(elements, delimiter, xpathOutput, xpaths, out);
if (table != null){
count = table.size() -1;
Iterator<String[]> tableInt = table.iterator();
while (tableInt.hasNext()){
csvWriter.writeNext(tableInt.next());
}
}else{
String [] fail = new String [] {"No Matched results for queried elements!"};
csvWriter.writeNext(fail);
}
doc.add("count", Integer.toString(count));
csvWriter.close();
PluginService.Output output = out.output(0);
output.setData(new TempFileInputStream(of), of.length(), "plain/text");
return doc;
}
示例9: save
import com.opencsv.CSVWriter; //导入方法依赖的package包/类
@Override
public boolean save(String file) {
try {
File f = new File(Login.getUser().getUserFolder() + File.separator
+ file + DataDudeFile.T_CSV);
f.createNewFile();
CSVWriter w = new CSVWriter(new FileWriter(f), ',',
CSVWriter.DEFAULT_QUOTE_CHARACTER,
CSVWriter.DEFAULT_ESCAPE_CHARACTER,
System.getProperty("line.separator"));
// Write It Out
for (int i = 0; i < lines.length; i++)
if (!(lines[i].getText().isEmpty())) // Make sure it isn't empty
w.writeNext(lines[i].getText().split("\\s*,\\s*"), false);
w.close();
} catch (Exception e) {
String text = "Exception while trying to save file:\n"
+ e.getMessage();
DataDude.showError(this, e, text);
return false;
}
return true;
}
示例10: entClasses
import com.opencsv.CSVWriter; //导入方法依赖的package包/类
private static void entClasses() throws IOException {
CSVWriter writer = new CSVWriter(new FileWriter(new File(base + "/entClasses.csv")));
for(String line : map.getEntClasses()) {
String[] arr = line.split("#");
// entity_id+"|"+class_id
String id1 = arr[0].substring(ENT_LENGTH);
String id2 = arr[1].substring(CLS_LENGTH);
// TODO find a fix for these relationships
try {
Integer.parseInt(id1);
Integer.parseInt(id2);
} catch(NumberFormatException e) {
continue;
}
writer.writeNext(new String[] {id1, id2});
}
writer.close();
}
示例11: writeCsvDocument
import com.opencsv.CSVWriter; //导入方法依赖的package包/类
protected void writeCsvDocument(BandData rootBand, OutputStream outputStream) {
try {
List<BandData> actualData = getActualData(rootBand);
CSVWriter writer = new CSVWriter(new OutputStreamWriter(outputStream), separator, CSVWriter.DEFAULT_QUOTE_CHARACTER);
writer.writeNext(header);
for (BandData row : actualData) {
String[] entries = new String[parametersToInsert.size()];
for (int i = 0; i < parametersToInsert.size(); i++) {
String parameterName = parametersToInsert.get(i);
String fullParameterName = row.getName() + "." + parameterName;
entries[i] = formatValue(row.getData().get(parameterName), parameterName, fullParameterName);
}
writer.writeNext(entries);
}
writer.close();
} catch (IOException e) {
throw new ReportFormattingException("Error while writing a csv document", e);
}
}
示例12: saveXlsxAsCsv
import com.opencsv.CSVWriter; //导入方法依赖的package包/类
protected void saveXlsxAsCsv(Document document, OutputStream outputStream) throws IOException, Docx4JException {
CSVWriter writer = new CSVWriter(new OutputStreamWriter(outputStream), ';', CSVWriter.DEFAULT_QUOTE_CHARACTER);
for (Document.SheetWrapper sheetWrapper : document.getWorksheets()) {
Worksheet worksheet = sheetWrapper.getWorksheet().getContents();
for (Row row : worksheet.getSheetData().getRow()) {
String rows[] = new String[row.getC().size()];
List<Cell> cells = row.getC();
boolean emptyRow = true;
for (int i = 0; i < cells.size(); i++) {
checkThreadInterrupted();
Cell cell = cells.get(i);
String value = cell.getV();
rows[i] = value;
if (value != null && !value.isEmpty())
emptyRow = false;
}
if (!emptyRow)
writer.writeNext(rows);
}
}
writer.close();
}
示例13: saveGameListToFile
import com.opencsv.CSVWriter; //导入方法依赖的package包/类
/**
* Saves current gameList to a file.
*
* @param outFile
* gameList will be written to this file
*/
private static void saveGameListToFile(File outFile) throws IOException {
CSVWriter csvWriter = new CSVWriter(new FileWriter(outFile), ',');
String[] header = Game.getColumnHeaders();
csvWriter.writeNext(header);
for (Game g : GameShelf.gameList.getGameList()) {
csvWriter.writeNext(g.toStringArray());
}
csvWriter.close();
System.out.println("Saved to " + outFile.getPath());
}
示例14: write2File
import com.opencsv.CSVWriter; //导入方法依赖的package包/类
public static void write2File(String filePath,List<String[]> lines) {
//写之前需要先写入header
List<String[]> addHeader = new ArrayList<>();
String[] header = new String[21];
header[0] = "id(编号)";
header[1] = "sysid(系统ID)";
header[2] = "imei(设备IMEI)";
header[3] = "trucknum(车辆编号)";
header[4] = "driverno(司机编号)";
header[5] = "orgcode(机构号)";
header[6] = "type(10为进出区域)";
header[7] = "beginLng(开始经度)";
header[8] = "beginLat(开始纬度)";
header[9] = "beginTime(开始时间)";
header[10] = "endLng(结束经度)";
header[11] = "endLat(结束纬度)";
header[12] = "endTime(结束时间)";
header[13] = "triggerTime(触发时间)";
header[14] = "triggerLng(触发经度)";
header[15] = "triggerLat(触发纬度)";
header[16] = "createTime(创建时间)";
header[17] = "updateTime(更新时间)";
header[18] = "seconds(持续时间|秒)";
header[19] = "additional_info(附加信息)";
header[20] = "additional_key(额外key)";
addHeader.add(header);
addHeader.addAll(lines);
try {
Charset encoder = Charset.forName("GBK");//解决乱码
OutputStreamWriter out = new OutputStreamWriter(new FileOutputStream(filePath), encoder);
CSVWriter writer = new CSVWriter(out, ',');
writer.writeAll(addHeader);
writer.close();
} catch (IOException e) {
e.printStackTrace();
}
}
示例15: writeGeoTagsFile
import com.opencsv.CSVWriter; //导入方法依赖的package包/类
public String writeGeoTagsFile(Date date, String dataDir, long measurementId) {
File file = new File(dataDir + String.format(Constants.GEO_TAGS + "_%s_%s%s",
DeviceUtil.getDeviceName(), new SimpleDateFormat(TimeUtil.DATE_FILENAME_FORMAT, Locale.US).format(date) + Constants.GEO_TAG_SUFFIX, Constants.CSV_EXT));
GeoTagDAO dao = new GeoTagDAO(RAApplication.getInstance());
try {
CSVWriter csvWrite = new CSVWriter(new FileWriter(file), SEPARATOR);
Cursor curCSV = dao.getGeoTagsByMeasurementIdCursor(measurementId);
csvWrite.writeNext(geoTagNames);
SimpleDateFormat timestampDate = new SimpleDateFormat(TimeUtil.DATE_TIMESTAMP, Locale.US);
do {
if (stopProcess) {
break;
}
if (curCSV.getCount() == 0) {
Log.d(TAG, "curCSV.getCount() == 0");
continue;
}
GeoTagModel geoTag = dao.cursorToRecord(curCSV);
long time = geoTag.getTime();
String dateStr = timestampDate.format(new Date(time));
double latitude = geoTag.getLatitude();
double longitude = geoTag.getLongitude();
String[] arrStr = {
dateStr,
String.format(Locale.US, "%3.8f", latitude),
String.format(Locale.US, "%3.8f", longitude),
};
csvWrite.writeNext(arrStr);
} while (curCSV.moveToNext());
csvWrite.close();
curCSV.close();
return file.getAbsolutePath();
} catch (Exception e) {
Log.e(TAG, "writeGeoTagsFile", e);
return null;
}
}