• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Reading Files

 
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey, I'm only now noticing how picky the java file readers are. I'm using Scanner to scan a file in code below:



And the format for the file is:
0:true:true/a-1:b-2:c-0
1:false:true/a-2:b-2:c-1
2:false:true/a-1:b-0:c-2

But unless I'm very specific with the format of my file, the whole thing breaks. If I hit return after typing everything in my file, or if I press space after typing a single line, everything goes downhill.

I tried using the skip() method to skip patterns like a space or two new lines feeds in a row, but it doesn't seem to work. Can anyone suggest anything else I might try?

Thanks so much and have a nice day!
[ May 31, 2007: Message edited by: Vanessa Astle ]
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Vanessa Astle:
Hey, I'm only now noticing how picky the java file readers are.


It's not that Java file readers are picky - computers are picky in general. A computer does exactly what you program it to do and nothing else, so you have to be very precise and think of every detail when you write a program. It's a good thing, imagine how hard it would be to program a computer that thinks by itself and guesses what you mean instead of doing exactly what you tell it to do...

You should add some error checking code at specific points to check if your variables contain what you expect. You could for example, after line.split("/"), check if you indeed got an array with two elements:
 
Attractive, successful people love this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic