File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes how to read input from a text file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "how to read input from a text file " Watch "how to read input from a text file " New topic

how to read input from a text file

sagarika chinya

Joined: Oct 17, 2002
Posts: 11
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 to java.lang.String.
StringTokenizer st = new StringTokenizer(fromFile);
can anyone tell me whats wrong??
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
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.
[ October 18, 2002: Message edited by: Barry Gaunt ]

Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
I agree. Here's the link:
subject: how to read input from a text file
It's not a secret anymore!