java


different behaviour of input scanner and parse in android studio and netbeans


I am reading the same pipe-delimited file using NetBeans (to test the basic code) and Android Studio (actual application) and getting different results.
Here is the offending code:
String URL = "http://.../CalendarUTF8(Dec2016).txt";
try {
java.net.URL url = new java.net.URL(URL);
Scanner input = new Scanner(url.openStream());
int i;
for (i = 0; input.hasNext(); i++) {
String temp = input.nextLine();
eventCalendar[i] = temp.split("\\|",9);
}
}
catch (java.io.IOException ex) {
System.out.println("IO Errors");
}
Code works perfectly in NetBeans. Same file being read in Android Studio randomly breaks an input line in the middle, and then reads it as 2 lines. I checked the file and there is no hidden characters at the place where it gets split. If I write the parser myself, works fine as well.
Looks like the problem is in using hasNext() in the header of for loop and using nextLine() in the body of for loop. When I replaced hasNext() with hasNextLine(), my record counts matched. Don't understand why, since hasNext() is supposed to look at something, not change, but it worked.

Related Links

Singleton Session Bean
I can't get text form radio buttoon
Is a new object created (in helper class) every time a static method is invoked?
Get Data through Binary Option Web App [closed]
Java Generics: Example if types are not erased at compilation
Java Generic Interface Return Generics
I'm a self-taught programmer so did i understand these concepts? can someone include example too [closed]
Java guarantee callback order execution
mpchartandroid chart legend overflows
Very Different Result When Testing Android App on Two Computers
Send data from my App android to my Raspberry PI 3
Netbeans Java program: user input from command terminal
Date parsing in android
How to validate Certificate with Java?
Java locks: Hand over hand locking through list
Caused by: javax.net.ssl.SSLPeerUnverifiedException: peer not authenticated

Categories

HOME
client
cookies
tinymce
fft
q
jsp-tags
adb
analysis
fancybox
paradox
slick-slider
elasticsearch-hadoop
gorm
user-input
hex-editors
event-handling
quickfix
ups
circuit
crystal-reports-2008
paging
jquery-ajaxq
chromium-embedded
wijmo
intel-pin
phpfox
replaceall
jaxb2
google-cloud-nl
twilio-api
perlin-noise
http-referer
ios5
vxworks
serve
ensembles
eclipse-scout
sql-server-agent
botbuilder
firebase-admin
reactive-cocoa-5
executenonquery
appcompat
azure-application-gateway
celery-task
dotnetzip
togetherjs
elgg
tactic
arrow-keys
mcafee
orthogonal
query-performance
nxt
instant
android-textview
ctest
fputcsv
angstrom-linux
moveit
sigabrt
actionbardrawertoggle
bluegiga
pagerank
oauth2client
qtableview
purge
dukescript
web-controls
website-monitoring
knuth
id3v2
googlemock
rdl
heisenbug
htmlcleaner
centos5
seed
interface-orientation
drools-planner
tinn-r
pvrtc
propertyeditor
cascalog
bubble-chart
amazon-appstore
qt-jambi
genshi
javax.script
krl
lpeg
google-friend-connect
blitz++
firefox4
backcolor
aquaticprime
gacutil
putchar
commodore

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