• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to write file to using buffered reader object Plzz help  RSS feed

 
Devendra Hamirani
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Campbell Ritchie
Marshal
Posts: 56545
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How did you manage to post here? You are not supposed to be able to find this forum. And please avoid abbreviations like Plzz.

You haven't asked a question. I can see some problems with your code. Apart from the poorly‑chosen class name (and please remind yourself about naming conventions) there is some poor design there. Move all that code out of the main method. I think you need at least one method for reading, one for handling the Strings and one for writing. Either that or use a Stream<String> to handle all the input. Use a StringBuilder instead of the StringBuffer.
Change the exception handling: use try with resources, which will also correct the serious mistake of not closing the reader and writer.
You haven't explained what you are doing with the text, or what that regex means, or what is going wrong. We can only help you if we know such information.
 
Carey Brown
Saloon Keeper
Posts: 3323
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One way to write to a file is with a PrintStream. This allows you to call the same println() method as your typical System.out.println() call.
 
Tony Docherty
Bartender
Posts: 3271
82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How to write file to using buffered reader object Plzz help

The simple answer to your question is you can't. A BufferedReader is for reading streams and not for writing them. If you want to write to a file you need a Writer such as BufferedWriter or an OutputStream such as PrintStream (as Carey suggested).
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!