This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Re: FileWriter write operation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Re: FileWriter write operation" Watch "Re: FileWriter write operation" New topic

Re: FileWriter write operation

venkat venkataraman

Joined: Apr 14, 2005
Posts: 3
I am trying to read in contents from a file, use STringTokenizer to tokenize the file using "/" as the delimiter, and print the contents to another file. I am able to read in the file, tokenize it and even print it to the standard output, but am not able to print it to an output file. The output file is created, but empty. Could anyone please tell me what I am missing here?


import java.util.StringTokenizer;
class Tokenize{
public static void main(String[] args){
FileReader reader = new FileReader("Input file name")/read in the file
BufferedReader buf = new BufferedReader(reader);//reading the contents into a buffer
FileWriter writer = new FileWriter("Output file name");
//PrintWriter out = new PrintWriter(writer);
String line = null;
String val = null;
StringTokenizer parser = new StringTokenizer(line, "/");//parse with ":" as the delimiter
val = parser.nextToken();


catch(Exception e){
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
> Could anyone please tell me what I am missing here?

venkat venkataraman

Joined: Apr 14, 2005
Posts: 3
Thanks Michael, it worked. I didn't realize that I missed close().....
Have you checked out Aspose?
subject: Re: FileWriter write operation
jQuery in Action, 3rd edition