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


Java CSVWriter類代碼示例

本文整理匯總了Java中au.com.bytecode.opencsv.CSVWriter的典型用法代碼示例。如果您正苦於以下問題:Java CSVWriter類的具體用法?Java CSVWriter怎麽用?Java CSVWriter使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


CSVWriter類屬於au.com.bytecode.opencsv包,在下文中一共展示了CSVWriter類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: writeCSV

import au.com.bytecode.opencsv.CSVWriter; //導入依賴的package包/類
/**
 * Writes the data set to a CSV file
 * 
 * @param file
 * @param dataset
 * @throws IOException
 */
public void writeCSV(File file, DataSet<RecordType, SchemaElementType> dataset)
		throws IOException {
	CSVWriter writer = new CSVWriter(new FileWriter(file));

	String[] headers = getHeader(dataset);
	if(headers!=null) {
		writer.writeNext(headers);
	}

	for (RecordType record : dataset.get()) {
		String[] values = format(record, dataset);

		writer.writeNext(values);
	}

	writer.close();
}
 
開發者ID:olehmberg,項目名稱:winter,代碼行數:25,代碼來源:CSVDataSetFormatter.java

示例2: exportCsv

import au.com.bytecode.opencsv.CSVWriter; //導入依賴的package包/類
public static void exportCsv(SortedMap<Number, Number> data, String filePath) {
	try {
		writer = new CSVWriter(new FileWriter(filePath), ',', '\0');

		List<String[]> entries = new ArrayList<>(data.size());
		for (Number x : data.keySet()) {
			String xString = String.valueOf(x);
			String yString = String.valueOf(data.get(x));
			entries.add(new String[] { xString, yString });
		}

		writer.writeAll(entries);
		writer.flush();
		writer.close();
	} catch (IOException e) {
		System.err.println(e.getMessage());
	}
}
 
開發者ID:tesis-dynaware,項目名稱:fancy-chart,代碼行數:19,代碼來源:CsvDao.java

示例3: csv

import au.com.bytecode.opencsv.CSVWriter; //導入依賴的package包/類
/**
 * Dump out a VoltTable as a CSV to the given writer
 * If the header flag is set to true, then the output will include 
 * the column names in the first row
 * @param out
 * @param vt
 * @param write_header
 */
public static void csv(Writer out, VoltTable vt, boolean header) {
    CSVWriter writer = new CSVWriter(out);
    
    if (header) {
        String cols[] = new String[vt.getColumnCount()];
        for (int i = 0; i < cols.length; i++) {
            cols[i] = vt.getColumnName(i);
        } // FOR
        writer.writeNext(cols);
    }
    vt.resetRowPosition();
    while (vt.advanceRow()) {
        String row[] = vt.getRowStringArray();
        assert(row != null);
        assert(row.length == vt.getColumnCount());
        writer.writeNext(row);
    } // WHILE
}
 
開發者ID:s-store,項目名稱:sstore-soft,代碼行數:27,代碼來源:VoltTableUtil.java

示例4: exportDatabaseToCsvString

import au.com.bytecode.opencsv.CSVWriter; //導入依賴的package包/類
public synchronized String exportDatabaseToCsvString() {
    StringWriter stringWriter = new StringWriter();
    CSVWriter csvWriter = new CSVWriter(stringWriter);
    csvWriter.writeNext(ThreeThingsEntry.COLUMNS);

    SQLiteDatabase db = mDbHelper.getReadableDatabase();
    Cursor cursor = db.rawQuery("SELECT * FROM " + ThreeThingsEntry.TABLE_NAME, null);
    while (cursor.moveToNext()) {
        List<String> data = new ArrayList(ThreeThingsEntry.COLUMNS.length);
        for (String column : ThreeThingsEntry.COLUMNS) {
            data.add(cursor.getString(cursor.getColumnIndexOrThrow(column)));
        }
        csvWriter.writeNext(data.toArray(new String[0]));
    }

    try {
        csvWriter.close();
    } catch (IOException e) {
        // Ignore.
    }

    return stringWriter.toString();
}
 
開發者ID:stephenmcgruer,項目名稱:three-things-today,代碼行數:24,代碼來源:ThreeThingsDatabase.java

示例5: writeCSVfile

import au.com.bytecode.opencsv.CSVWriter; //導入依賴的package包/類
/**
 * Writes newly calculated and equally distributed vector data to user specified CSV file.
 *
 * @param list finalized vector data to write to user specified output file
 */
public static void writeCSVfile(List<List<String>> list) {
  String outputFile = myResultDir;
  boolean alreadyExists = new File(outputFile).exists();

  try {
    CSVWriter csvOutput = new CSVWriter(new FileWriter(outputFile), ','); // Create new instance of CSVWriter to write to file output

    if (!alreadyExists) {
      csvOutput.writeNext(myHeader); // Write the text headers first before data

      for (int i = 0; i < list.size(); i++) // Iterate through all rows in 2D array
      {
        String[] temp = new String[list.get(i).size()]; // Convert row array list in 2D array to regular string array
        temp = list.get(i).toArray(temp);
        csvOutput.writeNext(temp); // Write this array to the file
      }
    }

    csvOutput.close(); // Close csvWriter
  } catch (IOException e) {
    e.printStackTrace();
  }
}
 
開發者ID:apache,項目名稱:incubator-sdap-mudrod,代碼行數:29,代碼來源:DataGenerator.java

示例6: writeCSV

import au.com.bytecode.opencsv.CSVWriter; //導入依賴的package包/類
/**
 * Writes the data set to a CSV file
 * 
 * @param file
 * @param dataset
 * @throws IOException
 */
public void writeCSV(File file, Processable<RecordType> dataset)
		throws IOException {
	CSVWriter writer = new CSVWriter(new FileWriter(file));

	String[] headers = getHeader();
	if(headers!=null) {
		writer.writeNext(headers);
	}

	for (RecordType record : dataset.get()) {
		String[] values = format(record);

		writer.writeNext(values);
	}

	writer.close();
}
 
開發者ID:olehmberg,項目名稱:winter,代碼行數:25,代碼來源:CSVFormatter.java

示例7: testDetails

import au.com.bytecode.opencsv.CSVWriter; //導入依賴的package包/類
public void testDetails() throws IOException, InterruptedException {
	File fold = new File(FOLDER);
	CSVWriter wr = new CSVWriter(new FileWriter(new File(FOLDER + GRAPH_DETAILS)),'&');
	printHeader(wr);
	for (File fpin: fold.listFiles(p -> p.getName().endsWith(".graph"))) { 
		//if (fpin.getName().equals("auto.graph")) continue;
		log.info("Analyzing graph : " + fpin.getName());
		GraphAnalyser ga = new GraphAnalyser(new FileInputStream(fpin), wr, log);
		String grName = fpin.getName().substring(0, fpin.getName().length() - ".graph".length());
		ga.runLoad(grName);
		ga = null;
		System.gc();
	}
	
	wr.close();
}
 
開發者ID:isislab-unisa,項目名稱:streaminggraphpartitioning,代碼行數:17,代碼來源:AllGraphDetails.java

示例8: DispersionTest

import au.com.bytecode.opencsv.CSVWriter; //導入依賴的package包/類
/**
 * Create the test case
 *
 * @param testName name of the test case
 * @throws IOException 
 */
public DispersionTest( String testName ) throws IOException
{
	super( testName );
	File fp = new File(CSV_FILENAME);
	if (fp.exists()) {
		fp.delete();
	}
	writer = new CSVWriter(new FileWriter(CSV_FILENAME,true));
	String[] header =  {
					"Graph Name",
					"Total nodes", 	
					"Total edges",
					"Ordering Type",
					"Heuristic Name",  
					"Displacement", 	
					"Cutted Edges",
					"Cutted Edges Ratio",
					"Total time",
					"Iteration time"
			};
	writer.writeNext(header);
}
 
開發者ID:isislab-unisa,項目名稱:streaminggraphpartitioning,代碼行數:29,代碼來源:DispersionTest.java

示例9: queryToCSV

import au.com.bytecode.opencsv.CSVWriter; //導入依賴的package包/類
private String queryToCSV(final SqlParameterSource queryParams, final String sql) {
    final int bufferSize = 16384;

    try (final StringWriter writer = new StringWriter(bufferSize);
            final CSVWriter csvWriter = new CSVWriter(writer, ';')) {

        jdbcTemplate.query(sql, queryParams, resultSet -> {
            try {
                csvWriter.writeAll(resultSet, true);
                csvWriter.flush();

                return null;

            } catch (IOException ioe) {
                throw new RuntimeException(ioe);
            }
        });

        return writer.getBuffer().toString();
    } catch (final IOException e) {
        throw new RuntimeException(e);
    }
}
 
開發者ID:suomenriistakeskus,項目名稱:oma-riista-web,代碼行數:24,代碼來源:PublicMetsahallitusHarvestSummaryFeature.java

示例10: writeInternal

import au.com.bytecode.opencsv.CSVWriter; //導入依賴的package包/類
@Override
protected void writeInternal(CSVHttpResponse response, HttpOutputMessage output) throws IOException {
    final Charset charset = getCharset(response);

    output.getHeaders().setContentType(createMediaType(charset));
    output.getHeaders().set("Content-Disposition", "attachment; filename=\"" + response.getFilename() + "\"");

    try (final OutputStreamWriter outputStreamWriter = new OutputStreamWriter(output.getBody(), charset);
         final CSVWriter writer = new CSVWriter(outputStreamWriter, ';')) {

        if (response.getHeaderRow() != null) {
            writer.writeNext(response.getHeaderRow());
        }

        writer.writeAll(response.getRows());
        writer.flush();
    }
}
 
開發者ID:suomenriistakeskus,項目名稱:oma-riista-web,代碼行數:19,代碼來源:CSVMessageConverter.java

示例11: testWrite

import au.com.bytecode.opencsv.CSVWriter; //導入依賴的package包/類
@Test
public void testWrite() throws IOException { 
  String[] row1 = new String[] { "oneone", "onetwo", "onethree" };
  String[] row2 = new String[] { "twoone", "twotwo", "twothree" };

  StringWriter sWriter = new StringWriter();
  CSVWriter writer = new CSVWriter(sWriter, ',', '\'');

  writer.writeNext(row1);
  writer.writeNext(row2);

  String written = sWriter.toString();

  CSVReader reader = new CSVReader(new StringReader(written), ',', '\'');
  List<String[]> rows = reader.readAll();
  assertTrue(Arrays.equals(rows.get(0), row1));
  assertTrue(Arrays.equals(rows.get(1), row2));
}
 
開發者ID:casific,項目名稱:murmur,代碼行數:19,代碼來源:OpenCSVTest.java

示例12: writePartialTimesToFile

import au.com.bytecode.opencsv.CSVWriter; //導入依賴的package包/類
public void writePartialTimesToFile(Path outputFilePath, FileSystem fileSystem) throws IOException {
    // Creates the file and the writer.
    FSDataOutputStream fileOutputStream = fileSystem.create(outputFilePath, true);
    BufferedWriter bufferedWriter = new BufferedWriter(new OutputStreamWriter(fileOutputStream));
    CSVWriter fileWriter = new CSVWriter(bufferedWriter);

    // Writes partial times.
    for (Map.Entry<PartialTimeKey, Long> mapEntry : partialTimesMap.entrySet()) {
        PartialTimeKey partialTimeKey = mapEntry.getKey();
        long time = mapEntry.getValue();
        this.writeNextPartialTimeToFileWriter(partialTimeKey, time, fileWriter);
    }

    // Finalises the file.
    fileWriter.close();
}
 
開發者ID:pasqualesalza,項目名稱:elephant56,代碼行數:17,代碼來源:MapReduceTimeReporter.java

示例13: main

import au.com.bytecode.opencsv.CSVWriter; //導入依賴的package包/類
public static void main(String[] args) throws IOException {
	
	CSVReader reader = new CSVReader(new FileReader(ADDRESS_FILE));
	String [] nextLine;
	while ((nextLine = reader.readNext()) != null) {
		System.out.println("Name: [" + nextLine[0] + "]\nAddress: [" + nextLine[1] + "]\nEmail: [" + nextLine[2] + "]");
	}
	
	// Try writing it back out as CSV to the console
	CSVReader reader2 = new CSVReader(new FileReader(ADDRESS_FILE));
	List allElements = reader2.readAll();
	StringWriter sw = new StringWriter();
	CSVWriter writer = new CSVWriter(sw);
	writer.writeAll(allElements);
	
	System.out.println("\n\nGenerated CSV File:\n\n");
	System.out.println(sw.toString());
	
	
}
 
開發者ID:mleoking,項目名稱:PhET,代碼行數:21,代碼來源:AddressExample.java

示例14: writeGraph2CSV

import au.com.bytecode.opencsv.CSVWriter; //導入依賴的package包/類
/**
	 * Warning: use writeColocationGraph2CSV to export colocation graphs into
	 * CSV files.
	 */
	public static void writeGraph2CSV(DefaultDirectedWeightedGraph<Long, DefaultWeightedEdge> usegraph, File file)
			throws IOException {
		CSVWriter writer = new CSVWriter(new FileWriter(file), ';');
//		System.out.println("écriture du fichier csv");
		// write header
		String[] line = new String[3];
		line[0] = "source";
		line[1] = "target";
		line[2] = "weight";
		writer.writeNext(line);
		for (DefaultWeightedEdge e : usegraph.edgeSet()) {
			line = new String[3];
			line[0] = String.valueOf(usegraph.getEdgeSource(e).longValue() + (long) 111);
			line[1] = String.valueOf(usegraph.getEdgeTarget(e).longValue() + (long) 111);
			line[2] = String.valueOf(usegraph.getEdgeWeight(e));
			writer.writeNext(line);
		}
		writer.close();
	}
 
開發者ID:IGNF,項目名稱:geoxygene,代碼行數:24,代碼來源:SocialGraph.java

示例15: writeSimpleWeightedGraph2CSV

import au.com.bytecode.opencsv.CSVWriter; //導入依賴的package包/類
public static void writeSimpleWeightedGraph2CSV(SimpleWeightedGraph<Long, DefaultWeightedEdge> colocationgraph,
		File file) throws IOException {
	CSVWriter writer = new CSVWriter(new FileWriter(file), ';');
	// write header
	String[] line = new String[4];
	line[0] = "source";
	line[1] = "target";
	line[2] = "weight";
	line[3] = "type";
	writer.writeNext(line);
	for (DefaultWeightedEdge e : colocationgraph.edgeSet()) {
		line = new String[4];
		line[0] = String.valueOf(colocationgraph.getEdgeSource(e).longValue() + (long) 111);
		line[1] = String.valueOf(colocationgraph.getEdgeTarget(e).longValue() + (long) 111);
		line[2] = String.valueOf(colocationgraph.getEdgeWeight(e));
		line[3] = "undirected";
		writer.writeNext(line);
	}
	writer.close();
}
 
開發者ID:IGNF,項目名稱:geoxygene,代碼行數:21,代碼來源:SocialGraph.java


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