• 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

how to read input from a text file

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I have written a program using StringTokenizer.It takes a string and breaks it into tokens.The argument for StringTokenizer is a String.And this if working fine.
My question is ..
I want to input a text file from command line and read the text file and after performing some operation output the results to a text file. I am new to java, can any body tell as to which methods/classes to use?
If i use FileInputStream , i am getting the following error
Incompatible type for constructor. Can't convert java.io.FileInputStream to java.lang.String.
StringTokenizer st = new StringTokenizer(fromFile);
can anyone tell me whats wrong??
thanks
sagarika
 
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
StringTokenizer's constructors like Strings as arguments.
To get some lines (Strings) use a FileReader feeding a BufferedReader and use the BufferReader's getLine method. From the lines you can make StringTokenizers which you can use to get tokens.
Sorry I don't write the code for you, but do post what you write if you have problems.
-Barry
[ October 18, 2002: Message edited by: Barry Gaunt ]
 
You have to be odd to be #1 - Seuss. An odd little 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