Re: file output in java : Notepad gives weird results



Arne Vajhøj wrote:
ankur wrote:
I used the following code to write output to a file.
FileOutputStream fout = new FileOutputStream(fname,true);
PrintStream ps = new PrintStream(fout);
Random r = new Random(10);
for(int i = 0 ; i <= r1-1; i++)
{
for (int j = 0 ; j <= c1-1; j++)
{
m1[i][j] = r.nextInt(10);
//System.out.println(m1[i][j]);
ps.print(m1[i][j]);
ps.printf("\n");
}

//ps.printf("\r");
}
ps.close();
fout.close();
}


with this code if I read the output file in notepad I get all junk
characters written out. Like this:

ਲ਼ਰਲ਼ਰਸ਼ਸ਼

But if I open this file in textpad the output is fine:

3
0
3
0
6
6

However if I uncomment
//ps.printf("\r");

Output in notepad is surprising. There are no new lines: 303066

But textpad is fine !

Apparently TextPad considers \n a line break while NotePad only
considers \r\n a line break.
....

Maybe NotePad is interpreting a \r followed by another character other
than \n as a weird character?

Note that the line termination problem can be fixed very easily by
replacing 'ps.printf("\r");' with 'ps.printf("%n");'.

Patricia
.



Relevant Pages

  • Re: file output in java : Notepad gives weird results
    ... with this code if I read the output file in notepad I get all junk ... But if I open this file in textpad the output is fine: ... Output in notepad is surprising. ... You could try explicit specifying character set. ...
    (comp.lang.java.programmer)
  • Re: Cant find string terminator ...
    ... I use TextPad as my editor. ... Lately I noticed this on my home machine when running a test script: ... It's like an EOF character is buried in there somewhere. ... Notepad has some quirky behaviour as well. ...
    (comp.lang.perl.misc)
  • Re: file output in java : Notepad gives weird results
    ... PrintStream ps = new PrintStream; ... with this code if I read the output file in notepad I get all junk ... But if I open this file in textpad the output is fine: ... Output in notepad is surprising. ...
    (comp.lang.java.programmer)
  • Re: Highlighting blanks via GO TO SPECIAL is not highlighting blank cells - HELP, Im totally s
    ... thought the ONE THING that would be benign would be the good old tilde! ... In the end, to get it done, I did the "via notepad" trick. ... Finally found the bug reporting page by signing in with Passport, ... is a wildcard that represents any one character. ...
    (microsoft.public.excel.misc)
  • Re: Problem copying MsgBox text in Vista
    ... Chror any character after it is displayed and thus can't be copied, ... pasted into Notepad and when saved to a file, ... troubleshooting a VBScript as long as what you display does not contain ... In Vista, it works pretty much the same, except when the copied message ...
    (microsoft.public.scripting.vbscript)