Re: importing a csv file into a wonder application
Re: importing a csv file into a wonder application
- Subject: Re: importing a csv file into a wonder application
- From: Fabian Peters <email@hidden>
- Date: Thu, 16 Apr 2015 09:59:32 +0200
Hi Kevin,
My CSV importers use something like this:
Scanner scanner = new Scanner(new FileInputStream(importFile), "UTF-8");
try {
// first use a Scanner to get each line
Integer lineNumber = 0;
while (scanner.hasNextLine()) {
String currentLine = scanner.nextLine();
lineNumber += 1;
…
} finally {
scanner.close();
}
And for handling the individual lines:
StrTokenizer tokenizer = StrTokenizer.getCSVInstance(aLine);
tokenizer.setDelimiterChar(';');
tokenizer.getTokenList();
for (int i = 0; i < tokenizer.getTokenArray().length; i++) {
String aToken = tokenizer.getTokenArray()[i];
if (!ERXStringUtilities.stringIsNullOrEmpty(aToken)) {
switch (i) {
case 0: {
…
}
}
}
HTH, Fabian
> Am 16.04.2015 um 06:11 schrieb Kevin @ alchemy POP <email@hidden>:
>
> I've got a simple Wonder project where I want to populate the database by importing a csv file. Before adding the data to the table I intend to do some cleanup on it, ie, checking for unwanted characters, etc. Is there an approved Wonder approach to reading a text file, or is it just straight java until it's time to actually add the records to the database?
>
> I looked through the Wonder docs but did not see anything related to basic text file i/o.
>
> Thanks,
>
>
> Kevin Spake
> Alchemy Billing LLC
> 916-397-9953: Phone
> 866-594-0847: Fax
>
> IMPORTANT WARNING: This message is intended for the use of the person or entity to which it is addressed and may contain information that is priviledged and confidential, the disclosure of which s governed by applicable laws. If the reader of this message is not the intended recipient, you are hereby notified that any dissemination, distribution, or copying of this message is STRICTLY PROHIBITED. If you have received this message in error, please notify us immediately at 1(916)723-7029 and delete the related message. You, the recipient, are obligated to maintain it in a safe, secure, and confidential manner. Re-disclosure without additional consent or as permitted by the law is prohibited. Unauthorized re-disclosure or failure to maintain confidentiality could subject you to penalties described in the Federal and State Laws.
>
> _______________________________________________
> Do not post admin requests to the list. They will be ignored.
> Webobjects-dev mailing list (email@hidden)
> Help/Unsubscribe/Update your Subscription:
>
> This email sent to email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden