Allora aperto con wordPad viene esattamente questo:
code;description;unit;price
Cerco di spiegare perchè ho inserito quelle due righe.
Allora con questo codice mi separa queste parole: "NOME ","COGNOME","DATA"
codice:
/**
* Take HEAD row of CSV file
*
* @param reader
* to file
* @param nRow
* of row to analyze
* @return HeadRow
* if row = null -> the operation is failed
*/
private static ArrayList<String> getCsvHeadRow(File file, int nRow) {
// Take reader
CSVReader reader = getReader(file);
ArrayList<String> row = new ArrayList<String>();
try {
String[] nextLine = reader.readNext();
// Take an row
for (int j = 0; j < nextLine.length; j++) {
row.add(trimAndLowerCase(nextLine[j]));
}
}
catch (IOException e) {
e.printStackTrace();
row = null;
}
return row;
}// end of method
Poichè io devo separare delle parole scritte in questo modo: NOME; COGNOME; DATA
Mi avevi detto di utilizzare il metodo con il quale settare il separatore, cioè questo
codice:
CSVReader ExcelReader = new CSVReader(readerExcel, ';');
Quindi ho modificato il codice in questo modo:
codice:
/**
* Take HEAD row of CSV file
*
* @param reader
* to file
* @param nRow
* of row to analyze
* @return HeadRow
* if row = null -> the operation is failed
*/
private static ArrayList<String> getCsvHeadRow(File file, int nRow) {
// Take reader
Reader readerExcel = new Reader() {
@Override
public int read(char[] buf, int offset, int count) throws IOException {
// TODO Auto-generated method stub
return 0;
}
@Override
public void close() throws IOException {
// TODO Auto-generated method stub
}
};
CSVReader ExcelReader = new CSVReader(readerExcel, ';');
ExcelReader = getReader(file);
ArrayList<String> row = new ArrayList<String>();
try {
String[] nextLine = ExcelReader.readNext();
// Take an row
for (int j = 0; j < nextLine.length; j++) {
row.add(trimAndLowerCase(nextLine[j]));
}
}
catch (IOException e) {
e.printStackTrace();
row = null;
}
return row;
}// end of method
/**
* Take reader to file
*
* @param file
* from with to take reader
*
* @return reader of file
*/
private static CSVReader getReader(File file) {
CSVReader reader = null;
try {
reader = new CSVReader(new FileReader(file));
return reader;
}
catch (FileNotFoundException e) {
e.printStackTrace();
return null;
}
}// end of method
Ho copiato tutto il codice per rendere più leggibile il programma.
Hai capito un po' meglio il mio metodo?
Solo che è come se non avessi cambiato nulla