i have a problem with CSV dowload with php. my CSV contains http headers and i need delete this information for after automatically one process update database. Also i need delete column for this CSV.
i don´t kwon how i can delete my http header from CSV and i don´t know how i can delete this column.
i can read my all content CSV with this code:
public static void main(String[] args) throws FileNotFoundException, IOException,
CsvValidationException {
String archCSV = System.getProperty("user.dir") + "\\MYLAR.csv";
CSVReader csvReader = new CSVReader(new FileReader(archCSV));
String[] fila = null;
while((fila = csvReader.readNext()) != null) {
System.out.println(fila[0]);
}
csvReader.close();
}
and i get all my content CSV. In console i get this:
HTTP/1.1 200 OK
Date: Wed
Server: Apache/2.4.18 (Unix) OpenSSL/1.0.2g PHP/5.6.19 mod_perl/2.0.8-dev Perl/v5.16.3
Vary: Host
X-Powered-By: PHP/5.6.19
Pragma: public
Last-Modified: Wed
Cache-Control: no-store
Cache-Control: pre-check=0
Cache-Control: private
Content-Transfer-Encoding: none
Content-Disposition: attachment; filename="tarifa_general.csv
Content-Length: 1682234
Set-Cookie:
Content-Type: text/csv; charset=utf-8
CATEGORY_PATH;MANUFACTURER;ID_PRODUCT;PRODUCT;REFERENCE;REFERENCE_PARENT;STOCK;EAN13;SHORT_DESCRIPTION;PRICE_CUSTOMER
PERIFÉRICOS > IMPRESORAS / FAX > IMPRESORAS > EPSON > MATRICIALES";EPSON;1;"IMPRESORA EPSON LQ-2190";C11CA92001;;0;8715946459172;000003;910.33
how will i can delete http header and my columns that i wan´t ?
thanks for help
EDIT with ; delimiter
public static void main(String[] args) throws FileNotFoundException, IOException, CsvValidationException, CsvException {
Path archCSV = Paths.get(System.getProperty("user.dir"), "MYLAR.csv");
try (BufferedReader fileReader = Files.newBufferedReader(archCSV)) {
// Skip HTTP Headers
for (String line; (line = fileReader.readLine()) != null; )
if (line.isEmpty())
break; // Found end of HTTP Headers
}
CSVParser parser = new CSVParserBuilder().withSeparator(';').build();
try (BufferedReader br = Files.newBufferedReader(archCSV, StandardCharsets.UTF_8);
CSVReader reader = new CSVReaderBuilder(br).withCSVParser(parser).build()) {
List<String[]> rows = reader.readAll();
for (String[] row : rows) {
for (String e : row) {
System.out.format("%s ", e);
}
System.out.println();
}
}
}
output
HTTP/1.1 200 OK
Date: Wed, 04 Nov 2020 10:33:57 GMT
Server: Apache/2.4.18 (Unix) OpenSSL/1.0.2g PHP/5.6.19 mod_perl/2.0.8-dev Perl/v5.16.3
Vary: Host
X-Powered-By: PHP/5.6.19
Pragma: public
Last-Modified: Wed, 04 Nov 2020 10:35:38 GMT
Cache-Control: no-store, no-cache, must-revalidate
Cache-Control: pre-check=0, post-check=0, max-age=0
Cache-Control: private
Content-Transfer-Encoding: none
Content-Disposition: attachment filename="tarifa_general.csv
Content-Length: 1682234
Set-Cookie
expires=Tue, 24-Nov-2020 10:33:57 GMT Max-Age=1727899 path=/ domain=www.mylar.es httponly
Content-Type: text/csv charset=utf-8
CATEGORY_PATH MANUFACTURER ID_PRODUCT PRODUCT REFERENCE REFERENCE_PARENT STOCK EAN13 SHORT_DESCRIPTION PRICE_CUSTOMER
PERIFÉRICOS > IMPRESORAS / FAX > IMPRESORAS > EPSON > MATRICIALES EPSON 1 IMPRESORA EPSON LQ-2190 C11CA92001 0 8715946459172 000003 910.33
SOLUTION
public static void main(String[] args) throws FileNotFoundException, IOException, CsvValidationException, CsvException {
Path archCSV = Paths.get(System.getProperty("user.dir"), "MYLAR.csv");
CSVParser parser = new CSVParserBuilder().withSeparator(';').build();
try (BufferedReader br = Files.newBufferedReader(archCSV, StandardCharsets.UTF_8);
CSVReader reader = new CSVReaderBuilder(br).withCSVParser(parser).build()) {
// Skip HTTP Headers
for (String line; (line = br.readLine()) != null; )
if (line.isEmpty())
break; // Found end of HTTP Headers
List<String[]> rows = reader.readAll();
for (String[] row : rows) {
for (String e : row) {
//System.out.format("%s ", e);
System.out.println(row[2]);
}
System.out.println();
}
}
}