au.com.bytecode.opencsv.CSVReader.close()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(6.1k)|赞(0)|评价(0)|浏览(101)

本文整理了Java中au.com.bytecode.opencsv.CSVReader.close()方法的一些代码示例,展示了CSVReader.close()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。CSVReader.close()方法的具体详情如下:
包路径:au.com.bytecode.opencsv.CSVReader
类名称:CSVReader
方法名:close

CSVReader.close介绍

[英]Closes the underlying reader.
[中]关闭基础读取器。

代码示例

代码示例来源:origin: stackoverflow.com

FileInputStream fis = new FileInputStream("awesomefile.csv"); 
InputStreamReader isr = new InputStreamReader(fis, "UTF-8");
CSVReader reader = new CSVReader(isr);

for (String[] row; (row = reader.readNext()) != null;) {
  System.out.println(Arrays.toString(row));
}

reader.close();
isr.close();
fis.close();

代码示例来源:origin: apache/hive

@Override
public Object deserialize(final Writable blob) throws SerDeException {
 Text rowText = (Text) blob;
 CSVReader csv = null;
 try {
  csv = newReader(new CharArrayReader(rowText.toString().toCharArray()), separatorChar,
      quoteChar, escapeChar);
  final String[] read = csv.readNext();
  for (int i = 0; i < numCols; i++) {
   if (read != null && i < read.length) {
    row.set(i, read[i]);
   } else {
    row.set(i, null);
   }
  }
  return row;
 } catch (final Exception e) {
  throw new SerDeException(e);
 } finally {
  if (csv != null) {
   try {
    csv.close();
   } catch (final Exception e) {
    LOG.error("fail to close csv writer ", e);
   }
  }
 }
}

代码示例来源:origin: forcedotcom/phoenix

System.err.println("Failed to upsert data in the Phoenix :: " + e.getMessage());
}finally {
  reader.close();

代码示例来源:origin: eu.agrosense.client/io-csv

@Override
public void close() throws IOException {
  if (csvReader != null) {
    csvReader.close();
  }
}

代码示例来源:origin: apache/tika

@Test
public void testSimpleWord() throws Exception {
  Response response = WebClient
      .create(endPoint + META_PATH)
      .type("application/msword")
      .accept("text/csv")
      .put(ClassLoader
          .getSystemResourceAsStream(TikaResourceTest.TEST_DOC));
  Reader reader = new InputStreamReader((InputStream) response.getEntity(), UTF_8);
  CSVReader csvReader = new CSVReader(reader);
  Map<String, String> metadata = new HashMap<String, String>();
  String[] nextLine;
  while ((nextLine = csvReader.readNext()) != null) {
    metadata.put(nextLine[0], nextLine[1]);
  }
  csvReader.close();
  assertNotNull(metadata.get(TikaCoreProperties.CREATOR.getName()));
  assertEquals("Maxim Valyanskiy", metadata.get(TikaCoreProperties.CREATOR.getName()));
  assertEquals("X-TIKA:digest:MD5", "f8be45c34e8919eedba48cc8d207fbf0",
      metadata.get("X-TIKA:digest:MD5"));
}

代码示例来源:origin: Qihoo360/Quicksql

public void close() {
 try {
  reader.close();
 } catch (IOException e) {
  throw new RuntimeException("Error closing CSV reader", e);
 }
}

代码示例来源:origin: pl.edu.icm.polindex/polindex-tools

private void closeCsvReader(CSVReader csvReader) {
  try {
    if (csvReader != null) {
      csvReader.close();
    }
  } catch (IOException e) {
    logger.warn("Error while closing CSV reader", e);
  }
}

代码示例来源:origin: pl.edu.icm.polindex/polindex-tools

public void close() {
    try {
      reader.close();
    } catch (IOException e) {
      logger.error("", e);
    }
  }
}

代码示例来源:origin: apache/tika

metadata.put(nextLine[0], nextLine[1]);
csvReader.close();

代码示例来源:origin: stackoverflow.com

CSVReader reader = null;
try {
  reader = new CSVReader(new FileReader(filepath), ',');
  // Code from the original try block, removed for brevity's sake
} catch (Exception ex) {
  ex.printStackTrace(); // Or some useful error handling
} finally { // closing the reader in the finally block
  if (reader != null) {
    reader.close();
  }
}

代码示例来源:origin: org.wso2.carbon.data/org.wso2.carbon.dataservices.core

@Override
public boolean isActive() {
  try {
    CSVReader reader = this.createCSVReader();
    reader.close();
    return true;
  } catch (Exception e) {
    log.error("Error in checking CSV config availability", e);
    return false;
  }
}

代码示例来源:origin: com.splunk/splunk

/** {@inheritDoc} */
@Override public void close() throws IOException {
  super.close();
  if (csvReader != null)
    csvReader.close();
  csvReader = null;
}

代码示例来源:origin: stackoverflow.com

for (int i = 1; i <= 2; i++){
 CSVReader reader = new CSVReader(new FileReader(args[i]));
 String [] nextLine;
 while ((nextLine = reader.readNext()) != null) {
     // nextLine[] is an array of values from the line
     //System.out.println(nextLine[0] + nextLine[1] + "etc...");

     for (String value:nextLine)
      System.out.print(value+" ");
     System.out.println();
 }
 reader.close();
}

代码示例来源:origin: stackoverflow.com

public static List<String[]> read(String document) throws IOException{
   List<String[]> data = null;
   try{
     CSVReader reader = new CSVReader(new FileReader(document));
     data = reader.readAll();
     reader.close();
   } catch(IOException e){
     e.printStackTrace();
   }
   return data;
 }

代码示例来源:origin: jzy3d/jzy3d-api

/**********************************************/
protected static int readNLines(String filename) throws IOException {
  CSVReader reader = new CSVReader(new FileReader(filename));
  int n = 0;
  while (reader.readNext() != null)
    n++;
  reader.close();
  return n;
}

代码示例来源:origin: stackoverflow.com

String csvFilename = "path/to/sample.csv";
CSVReader csvReader = new CSVReader(new FileReader(csvFilename));
String[] row = null;
while((row = csvReader.readNext()) != null) {
  System.out.println(row[0]
       + " # " + row[1]
       + " #  " + row[2]);
}
//...
csvReader.close();

代码示例来源:origin: stackoverflow.com

public static List<String[]> read(String document) throws IOException{
  List<String[]> data;
  try{
    CSVReader reader = new CSVReader(new FileReader(document));
    data = reader.readAll();
    reader.close();
  } catch(IOException e){
    e.printStackTrace();
  }
  return data;
}

代码示例来源:origin: stackoverflow.com

public static List<String[]> read(String document) throws IOException{
  List<String[]> data = null;

  try{
    CSVReader reader = new CSVReader(new FileReader(document));
    data = reader.readAll();
    reader.close();
  } catch(IOException e){
    e.printStackTrace();
  }

  return data;
}

代码示例来源:origin: jzy3d/jzy3d-api

protected static int readNLines(String filename) throws IOException {
    CSVReader reader = new CSVReader(new FileReader(filename));
    int n = 0;
    while (reader.readNext() != null)
      n++;
    reader.close();
    return n;
  }
}

代码示例来源:origin: stackoverflow.com

String[] values = {"one", "two,three", "four , five"};
 CSVWriter writer = new CSVWriter(new FileWriter("yourfile.csv"));
 writer.writeNext(values);
 writer.close();

CSVReader reader = new CSVReader(new FileReader("yourfile.csv"));
String [] entries;
// reading just the first line
if ((entries = reader.readNext()) != null) {
  System.out.println(entries[0] + ", " + entries[1] + ", " + entries[2]);
}
reader.close();

相关文章