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

Is it bad practice to use Object.getClass() in Java? [closed]
Dagger 2 - Injecting class to declared interface
Is there a way for a Java app to gain root permissions?
Tests for Android Content Provider strange behavior
Issue when printing out from a CSV file. It prints out an address instead of what it is in the CSV file. Does anyone know how to fix it?
Can't compare string turned into integer java
How to check another button while action performed
BeanCreationException : Invocation of init method failed
How to restrict if condition only one time execution in java
How to handle transaction in Spring with weblogic and JPA
How to use hibernate to query for an object with a nested object that has a nested collection of objects
How to get a the output to a console as a string in java [closed]
How to make button changes repaint -during- method, not after?
Store Jtextfield input in Arraylist then print contents of Arraylist
1D array frequency counter for other methods
Android RSA encryption from public string

Categories

HOME
cakephp
date
asp.net-core
azure-data-factory
tizen
ngrx
programming-languages
jgroups
umd
onelogin
append
pheatmap
python-unittest
gorm
kibana-4
vault
floating-action-button
apache-cayenne
phaser
windows-server-2012
msp430
circuit
netflix
footer
pythonanywhere
beyondcompare
nas
facebook-instant-articles
chromium-embedded
language-agnostic
php-openssl
spark-jobserver
bootstrap-duallistbox
pingfederate
vision
flink-streaming
google-cloud-endpoints-v2
create-table
vsts-build-task
repo
textmate
android-nestedscrollview
geopositioning
mmenu
simplexml
adobe-premiere
hot-module-replacement
objectlistview
mapzen
g-code
texmaker
botbuilder
ibpy
scorm
apple-news
wso2carbon
google-datalayer
smartcontracts
react-scripts
winscp-net
elgg
android-cursor
color-profile
or-tools
sts-springsourcetoolsuite
elements
prettytensor
hover-over
wapiti
jmeter-maven-plugin
qdialog
embedded-code
ios9.1
dereference
c++03
umbraco6
tween
rdl
castle
oracle-warehouse-builder
quantlib-swig
sitemesh
tws
xamlparseexception
dice
removeclass
subgurim-maps
servicehost
xsdobjectgen
dbal
nsviewanimation
mirah
perfect-hash
web-architecture
port-number
w3wp
msdev
uiq3

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App