Roedy Green <roedy@mindprod.com> writes:[color=blue]
> Check out the PrintWriterPlus class in the hunkio package.
>
> See
http://mindprod.com/products.html#HUNKIO[/color]
Roedy, if you look at the original, very old posting, you will see that
the problem is not the FileWriter. There are a number of problems in
the original code, including:
- Using an InputStream and not a Reader to read some text file
- Doing line-by-line reading via the InputStream with a home-made EOL
detection that will break on any file not using the Unix convention,
instead of using a LineReader.
- Usage of a DataInput stream for reading from a URL, serving no
apparent purpose other then messing up the input data.
- Improper handling of empty lines (might be an artefact of the
problems with handling EOL).
- Rather strange mixture of using String and StringBuffer, including
converting a StringBuffer to a String and back to a StringBuffer on
the next line, multiple times converting the same StringBuffer (with
the same contents) to a String, etc.
- Improper attempt to convert a URL to a local file name (here the
broken EOL detection can sneak control chars into the name, and some
valid URL chars are not handled at all, like '=', '&', or '%').
And the control char \r from the name is why the creation of the
FileWriter breaks.
- Usage of the deprecated DataInputStream.readLine() to read a String.
- Usage of FileWriter to write bytes - which have just been converted
from the String gotten from DataInputStream.readLine() ...
- Manual memory handling: Manually clearing existing objects instead of
just creating new ones.
And I might have missed a few things.
In other words: THAT CODE DESERVES TO BE TAKEN OUT AND SHOT! The
remains have to be treated as toxic waste. Please, leave it alone.
/Thomas