java


how to seperate a csv file using commas if it has null values and we need data corresponding to upper column?


My code is
BufferedReader fileReader = new BufferedReader(new FileReader(strFileName));
while ((strLine = fileReader.readLine()) != null) {
// [2011.06.28] based on OAP's mail, now ignore "quotations"
strLine = strLine.replace("\"", "");
int j = 0;
String componentID = null;
String analyteResult = null;
lineNumber++;
//break comma separated line using ","
st = new StringTokenizer(strLine, ",");
while (st.hasMoreTokens()) {
//st.nextToken();
String value=st.nextToken();
if(tokenNumber==1)
{
if(lineNumber==1){
batchNo=value;
}
else if(lineNumber==2){
instrumentNo=value;
}
}
else if(lineNumber==4)
{
if(value.contains("_")){
String temp[] = value.split("_");
analyteCode = temp[0].trim();
a[j] = tokenNumber;
j++;
}
}
else if(lineNumber>4)
{
if(tokenNumber==0){
componentID=value;
}
}
tokenNumber++;
//System.out.println("Line Number : "+lineNumber+" Token Number: "+tokenNumber+"Value: "+st.nextToken());
}
//reset token number
tokenNumber = 0;
}
But I need analyte result corresponding to previous columns analyte codes.... as it could be null also....so its vanishing all commas and not parsing the result corresponding to previous column analyte code.
Mudit,
I am not sure if you have any compulsion of not using any open sources libs, so I strongly recommend the following widely used open source CSV parsers. It will save you a lot of effort in terms of coding and performance. Pls check them out for your specific need.
Apache Commons CSV parser.
OpenCSV parser

Related Links

JPA map collection of Enums
In Java critical sections, what should I synchronize on?
Spawn a process in Java that survives a JVM shutdown
Using the eclipse remote debugger and getting com.sun.jdi.InternalException: Got error code in reply:35 occurred while retrieving value. for all expressions
Adding rows to a JTable
How to register a JavaScript callback in a Java Applet?
Pattern for connecting to different databases using JDBC
SecureRandom: init once or every time it is needed?
Connecting to SQLServer using JDBC-ODBC Bridge
Fastest way to determine if an integer's square root is an integer
What package naming convention do you use for personal/hobby projects in Java? [closed]
protobuf serialization of language specific data structures
Embedding web browser window in Java
Convert Midi Note Numbers To Name and Octave
Should we declare a public constructor when the class is declared as package private?
BIRT in a desktop application

Categories

HOME
maven
winforms
client
asp.net-core
activiti
iterator
webstorm
rubygems
ravendb
mvvmcross
opengl-es-2.0
podio
mapserver
postgres-xl
size
dynamics-crm-online
vaadin7
telephony
django-admin
pugjs
connection-string
google-cloud-speech
shared-hosting
swiftlint
autoconf
java-3d
css-animations
mmap
format-specifiers
lcd
rundeck
microsoft-sync-framework
javacv
brunch
fopen
compatibility
c++-amp
google-cloud-nl
newline
madlib
ioio
contact-form
pim
geopositioning
rotational-matrices
http-digest
tasker
trim
preconditions
janrain
import-from-excel
node-sass
executenonquery
long-polling
parentheses
azure-application-gateway
typed-lambda-calculus
pearson
pillow
orthogonal
topbeat
trash
mongocsharpdriver
player
essence
whois
prerequisites
endeca-workbench
thredds
libressl
composite
web-controls
pretty-print
ng-animate
network-interface
castle
typeof
tld
dml
p4java
ember-charts
blending
easy-install
mylyn
interface-orientation
anonymous-methods
pvrtc
chuck
word-processor
windows-phone-7.1.1
jquery-ui-layout
stage
qt-jambi
spyware
javax.script
cxxtest
infrastructure
revisions
nsviewanimation

Resources

Database Users
RDBMS discuss
Database Dev&Adm
javascript
java
csharp
php
android
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App