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

Tracking time spent at a location in Android
Compilation Error: StanfordCoreNLP cannot be resolved to a type
Finding all the common substrings of given two strings
multple viewholder recyclerview not loading off screen views
Sedgewick Quicksort not making total sense
Is the following flowchart correct for the given code?
Sending emails with Gmail API with a specified email account
simplify method call with return value
Unable to start Selenium Server on CentOS7
HTMLUnit - Clicking on link does not work
stale element reference: element is not attached to the page document while using if else condition
How to map one-to-many relation properly in Hibernate?
How to check if an index is already occupied?
How to convert a HTML string to an image in Android AsyncTask?
Writing my own 2-node or 3-node Binary Search Tree
Evaluating XPath an XmlResourceParser causes Exception

Categories

HOME
sendgrid
openlayers
google-play
onedrive
rsyslog
sqlite-net-extensions
jira
uber-api
add
reveal.js
volttron
google-apps-marketplace
zend-framework3
fortumo
ups
lombok
windows-7-x64
undefined
tokenize
zurb-foundation-6
apache-commons-io
compatibility
kendo-datasource
tasklet
skia
lightswitch-2013
bosh
catel
winrt-xaml-toolkit
typed.js
html5-fullscreen
fusionpbx
libvpx
impersonation
android-fingerprint-api
dism
spring-security-kerberos
acoustics
convertapi
taffy
jedis
prolog-setof
jlink
zendesk-app
linode
django-scheduler
jquery-filter
firmata
grails-tomcat-plugin
vmware-tools
url-masking
google-web-starter-kit
nsfilemanager
connect-by
hexdump
php-internals
ios4
pyke
phpcas
cyclomatic-complexity
jmeter-maven-plugin
atk4
unity3d-gui
ami
composite
streambase
modalpopup
nstableviewcell
knuth
gui-test-framework
client-side-templating
java-metro-framework
internet-connection
code-access-security
phpthumb
comexception
mechanize-ruby
undefined-reference
bundles
concurrent-collections
jplaton
jspinclude
bubble-chart
buildr
punbb
data-loss
external-accessory
winbugs14
locate
iphone-web-app
yslow
zend-translate
filtered-index
rescale
adrotator
pascal-fc
sector
wsdl.exe

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