Posted by Brian Dickey on 1999-11-01
Date sent: Sun, 31 Oct 1999 01:37:31 +0200 (MEST)
Send reply to: tcg@xxxx.xx.xx
From: tcg@xxxx.xx.xx
To: bdickey@xxxxxxxxxxx.xxx
Subject: Java
First thing you want to do is create a BufferedReader class. This allows
you to read a line from a file at a time, and you will need the
StringTokenizer class which specializes in cutting out words deliminated
by spaces and white space. For more information see the java
documentation provided by sun, where there is more info and some
good examples.
Brian Dickey
// Open the file
BufferedReader in = new BufferedReader(new FileReader("foo.in"));
// Read a line from the file
String line = in.readLine();
// read all the tokens (words) from the file
StringTokenizer st = new StringTokenizer(line);
while (st.hasMoreTokens()) {
println(st.nextToken());
}
> Date: Sat, 30 Oct 1999 16:28:06 +0800
> From: Ng Oon Keat <knok@xx.xxx.xx>
> Subject: Java
>
> Hi. I am having problems in Java programming. How to read the content from
> a text file and then write to the other text file ? Besides, how to do
> string manipulation in Java ? For example if I have an original string
> "HELLO WORLD", now I would like to extract "WORLD" from the original
> string, what are the functions should i use ? Thanx
>
> Regards,
> Keat
>
Sponsored by Wrox Press - www.wrox.com. Programmer to Programmer (TM)
Previous post | Next post | Timeline | Home