#266 QuickNotepad bad write/read file

closed-fixed
nobody
None
9
2004-04-19
2004-02-12
No

I have found a bug connected to write/read of a file in
QuickNotepad.
The mistake is shown that all symbols which are not
getting in a range
32-127 are incorrectly read.

The mistake is covered in not symmetric use
Reader/Writer. At writing it
is used DataOutputStream+FileOutputStream and the text
is kept in an
internal format:
...
DataOutputStream dos = new DataOutputStream(
new FileOutputStream(filename));
dos.writeBytes(textArea.getText());
dos.close();
...

For reading it is used
BufferedReader+InputStreamReader+FileInputStream
...
fis = new FileInputStream(filename);
bf = new BufferedReader(new InputStreamReader(fis));
StringBuffer sb = new StringBuffer(2048);
String str;
while((str = bf.readLine()) != null)
{
sb.append(str).append('\n');
}
...

InputStreamReader reads files in view of system
encoding. For correct
work it is necessary to synchronize use Reader/Writer.
I think use
DataOutput* inexpedient - it is impossible to read/edit
a file other
programs. IMHO it is better to use:
- write:
FileWriter.write(String);
- read:
BufferedReader+FileReader.

In this case problems with encoding should not be.

Discussion

  • Vitaly Berdinskikh

    • summary: QuickNotepad bad write/read --> QuickNotepad bad write/read file
     
  • Vitaly Berdinskikh

    • priority: 5 --> 9
    • status: open --> open-remind
     
  • Vitaly Berdinskikh

    Logged In: YES
    user_id=963882

    Please correct file QuickNotepad.java:
    1.
    private void readFile() {
    ...
    bf = new BufferedReader(new InputStreamReader(fis,"UTF-16"));
    ...
    }

    2.
    public static void saveFile() {
    ...
    OutputStreamWriter osw = new OutputStreamWriter(
    new FileOutputStream(filename),"UTF-16");
    osw.write(textArea.getText(),0,textArea.getText().length());
    ...

     
  • Slava Pestov

    Slava Pestov - 2004-04-19
    • status: open-remind --> closed-fixed
     

Log in to post a comment.