Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

reading from file  RSS feed

 
Pranav Sharma
Ranch Hand
Posts: 261
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
how would i read numbers from a file, they arranged in tabular form with x and y cordinates.given below.
23
122 121
23 242
44 22
.
.
.
the first number gives the number of x y pairs in the file.
and then the x and y cordinates are listed below.
thank u
 
Pranav Sharma
Ranch Hand
Posts: 261
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi
if theres some one out here in the i/o side of the ranch.
I changed my input numbers format(to one number a line), and used the code below.
however it still does not work, i think the string takes a " " at the end of the number therefore cannot parse the string into a number.
any help on this... or the original problem
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well one way would be to create a BufferedReader wrapping a FileReader, then use readLine() to read the lines of the file (after the first line, use a for loop.) Use StringTokenizer to split the lines into individual "words" as needed, and use Integer.parseInt() to turn strings into integers.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!