當前位置: 首頁>>代碼示例>>Java>>正文


Java CSVWriter.close方法代碼示例

本文整理匯總了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;
    }
 
開發者ID:CSCfi,項目名稱:exam,代碼行數:19,代碼來源:CsvBuilder.java

示例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();
}
 
開發者ID:matsim-org,項目名稱:pt2matsim,代碼行數:25,代碼來源:GtfsTools.java

示例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();
    }
  }
}
 
開發者ID:HPI-Information-Systems,項目名稱:AdvancedDataProfilingSeminar,代碼行數:20,代碼來源:Merger.java

示例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();
}
 
開發者ID:matsim-org,項目名稱:pt2matsim,代碼行數:19,代碼來源:GtfsTools.java

示例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();
	}

}
 
開發者ID:curiosag,項目名稱:ftc,代碼行數:24,代碼來源:CSV.java

示例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();
	}
}
 
開發者ID:thorstenwagner,項目名稱:ij-trajectory-classifier,代碼行數:22,代碼來源:ExportImportTools.java

示例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();
    }
}
 
開發者ID:andretf,項目名稱:batatas-android,代碼行數:23,代碼來源:Utils.java

示例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;
}
 
開發者ID:uom-daris,項目名稱:daris,代碼行數:27,代碼來源:SvcObjectCSVExport.java

示例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;
}
 
開發者ID:realAhmedRoach,項目名稱:DataDude,代碼行數:26,代碼來源:CSVNode.java

示例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();
	
}
 
開發者ID:mommi84,項目名稱:Mandolin,代碼行數:23,代碼來源:ProbKBData.java

示例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);
    }
}
 
開發者ID:cuba-platform,項目名稱:yarg,代碼行數:23,代碼來源:CsvFormatter.java

示例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();
}
 
開發者ID:cuba-platform,項目名稱:yarg,代碼行數:26,代碼來源:XlsxFormatter.java

示例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());
}
 
開發者ID:Stevoisiak,項目名稱:Virtual-Game-Shelf,代碼行數:17,代碼來源:MainMenuBar.java

示例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();
    }
}
 
開發者ID:alamby,項目名稱:upgradeToy,代碼行數:38,代碼來源:CsvMergeByDay.java

示例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;
    }
}
 
開發者ID:WorldBank-Transport,項目名稱:RoadLab-Pro,代碼行數:38,代碼來源:ExportMeasurementDB.java


注:本文中的com.opencsv.CSVWriter.close方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。