예제 #1
0
  /**
   * Update the ranks in the csv file when the tweet is already in the base but saved with another
   * mark
   *
   * @param mark : note of the tweet
   * @param row : line of the tweet in the base
   * @throws IOException
   */
  public static void updateCSV(int mark, int row) throws IOException {
    CSVReader reader = new CSVReader(new FileReader(AppliSettings.filename), ';');
    List<String[]> csvBody = reader.readAll();
    csvBody.get(row)[4] = Integer.toString(mark);
    reader.close();

    CSVWriter writer = new CSVWriter(new FileWriter(AppliSettings.filename), ';');
    writer.writeAll(csvBody);
    writer.flush();
    writer.close();
  }
예제 #2
0
 /**
  * Method to write a CSV List of Array of String to System Console..
  *
  * @param content the List of Array of String to convert.
  * @param separator the char separator.
  */
 public static void writeCSVDataToConsole(List<String[]> content, char separator) {
   try {
     Writer writer = new OutputStreamWriter(System.out, StringUtilities.UTF_8);
     CSVWriter csvWriter;
     if (StringUtilities.NULL_CHAR2 == separator) {
       csvWriter =
           new CSVWriter(writer, CSVWriter.DEFAULT_SEPARATOR, CSVWriter.NO_QUOTE_CHARACTER);
     } else {
       csvWriter = new CSVWriter(writer, separator, CSVWriter.NO_QUOTE_CHARACTER);
     }
     csvWriter.writeAll(content, false);
     csvWriter.close();
   } catch (IOException e) {
     logger.error("Can't write the CSV to Console -> " + e.getMessage(), e);
   }
 }
예제 #3
0
 /**
  * Method to write a CSV Data List of Array of String to a String.
  *
  * @param content the List of Array of String to convert.
  * @param separator the char separator.
  * @return the String content of the List of Beans.
  */
 public static String writeCSVDataToString(List<String[]> content, char separator) {
   try {
     Writer writer = new StringWriter();
     CSVWriter csvWriter;
     if (StringUtilities.NULL_CHAR2 == separator) {
       csvWriter =
           new CSVWriter(writer, CSVWriter.DEFAULT_SEPARATOR, CSVWriter.NO_QUOTE_CHARACTER);
     } else {
       csvWriter = new CSVWriter(writer, separator, CSVWriter.NO_QUOTE_CHARACTER);
     }
     csvWriter.writeAll(content);
     csvWriter.close();
     return writer.toString();
   } catch (IOException e) {
     logger.error("Can't write the CSV String -> " + e.getMessage(), e);
     return "";
   }
 }
예제 #4
0
 /**
  * Method to write a CSV Data List of Beans to a String.
  *
  * @param beans the List of Beans to convert.
  * @param separator the char separator.
  * @param <T> the generic variable.
  * @return the String content of the List of Beans.
  */
 public static <T> String writeCSVDataToStringWithBeans(List<T> beans, char separator) {
   try {
     Writer writer = new StringWriter();
     try (CSVWriter csvWriter = new CSVWriter(writer, separator)) {
       List<String[]> data = toStringArray(beans);
       csvWriter.writeAll(data);
     }
     return writer.toString();
   } catch (IOException e) {
     logger.error(
         "Can't write the CSV String from the Bean:"
             + beans.get(0).getClass().getName()
             + " -> "
             + e.getMessage(),
         e);
     return "";
   }
 }
예제 #5
0
 /**
  * Method to write a CSV File from List of Array of String.
  *
  * @param content the List of Array of String to convert.
  * @param separator the char separator.
  * @param fileOutputCsv the output File Csv to create.
  * @return the File Csv created.
  */
 public static File writeCSVDataToFile(
     List<String[]> content, char separator, File fileOutputCsv) {
   try {
     Writer writer =
         new FileWriter(fileOutputCsv, true); // the true value make append the result...
     CSVWriter csvWriter;
     if (StringUtilities.NULL_CHAR2 == separator) {
       csvWriter =
           new CSVWriter(writer, CSVWriter.DEFAULT_SEPARATOR, CSVWriter.NO_QUOTE_CHARACTER);
     } else {
       csvWriter = new CSVWriter(writer, separator, CSVWriter.NO_QUOTE_CHARACTER);
     }
     csvWriter.writeAll(content);
     csvWriter.close();
     return fileOutputCsv;
   } catch (IOException e) {
     logger.error("Can't write the CSV to File:" + fileOutputCsv + " -> " + e.getMessage(), e);
     return null;
   }
 }
예제 #6
-1
  public void writeText(String filepath) {

    CSVWriter writer;
    try {
      writer = new CSVWriter(new FileWriter(filepath), ',', CSVWriter.NO_QUOTE_CHARACTER);
      // feed in your array (or convert your data to an array)

      writer.writeAll(ioNames.unformattedStrings());
      writer.close();
    } catch (IOException ex) {
      System.out.println("Write text error with " + filepath + " : " + ex.getMessage());
    }
  }