• 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

Scanner behaviour before the jre 1.5 era

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I have a nice little question for all you ranchers to shed your light upon.
For an assignment I have done I made use of the almighty Scanner object to walk through a String containing some nice text (including newline's etc.).

However, it has now come to my attention that the program is supposed to work with jre 1.4. Argh, that destroys my shiny Scanner!

So now I need some suggestions to implement the same behaviour without using a Scanner object.

I need to be able to check whether the input String contains more lines (i.e. scanner.hasNextLine()) and if so output the next line (i.e. line = scanner.nextLine()).

I welcome your suggestions. Something with a BufferedInputStream perhaps?
[ November 15, 2007: Message edited by: David Coppens ]
 
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
Have a look at BufferedReader - it has a method readLine() to read from an input stream line by line.
 
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You could look at the source code for Scanner and see how it is implemented. There should be a file called src.zip in your JDK installation directory.
 
reply
    Bookmark Topic Watch Topic
  • New Topic