This week's book / license giveaways are in the JDBC and Relational Databases and Java in General forums.
We're giving away four copies each of PostGIS in Action and Java Advanced Topics Training and have the authors on-line!
See this thread and this one for details.
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
Author

how to read input from a text file

sagarika chinya
Greenhorn

Joined: Oct 17, 2002
Posts: 11
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
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.
-Barry
[ 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: http://aspose.com/file-tools
 
subject: how to read input from a text file