PrintStream println() doesn't cause new line

This is where you talk about the NXJ software itself, installation issues, and programming talk.

Moderators: roger, imaqine, 99jonathan

kostas
New User
Posts: 6
Joined: Thu Nov 14, 2013 1:31 am

PrintStream println() doesn't cause new line

Postby kostas » Sun Nov 24, 2013 5:26 am

Can someone tell me why that may be the case?

I've tried:

Code: Select all

PS.print(Double.toString(value))
PS.println()
PS.print(Double.toString(value)


and

Code: Select all

PS.println(Double.toString(value))
PS.println((Double.toString(value)


but the output always seems to be:

valuevalue


This is driving me crazy. Thanks in advance for your help.

User avatar
gloomyandy
leJOS Team Member
Posts: 4424
Joined: Fri Sep 28, 2007 2:06 pm
Location: UK

Re: PrintStream println() doesn't cause new line

Postby gloomyandy » Sun Nov 24, 2013 7:13 am

What device or file are you attaching PS to? How have you created PS?

kostas
New User
Posts: 6
Joined: Thu Nov 14, 2013 1:31 am

Re: PrintStream println() doesn't cause new line

Postby kostas » Sun Nov 24, 2013 7:19 am

Good question, sorry for missing that. Here you go:

static File FN = new File("test.txt");
static FileOutputStream FOS=null;

try {
FOS = new FileOutputStream(FN);
} catch (FileNotFoundException e) {
ThrowError("FOS ERROR");
}

static PS = new PrintStream(FOS);

User avatar
gloomyandy
leJOS Team Member
Posts: 4424
Joined: Fri Sep 28, 2007 2:06 pm
Location: UK

Re: PrintStream println() doesn't cause new line

Postby gloomyandy » Sun Nov 24, 2013 1:05 pm

Is this code running on the NXT? How are you accessing the file and viewing it? What system are you viewing it on?

kostas
New User
Posts: 6
Joined: Thu Nov 14, 2013 1:31 am

Re: PrintStream println() doesn't cause new line

Postby kostas » Sun Nov 24, 2013 8:02 pm

This code is running on the NXT. I'm accessing the file via nxjbrowse and view it with the Notepad.

Thank you for looking into it!

User avatar
gloomyandy
leJOS Team Member
Posts: 4424
Joined: Fri Sep 28, 2007 2:06 pm
Location: UK

Re: PrintStream println() doesn't cause new line

Postby gloomyandy » Sun Nov 24, 2013 8:08 pm

The line endings in the file will be linux line endings not Windows/DOS line endings. I suspect this is your problem. You may find other programs like vim that you can run on Windows that will handle Linux line endings...

skoehler
leJOS Team Member
Posts: 1484
Joined: Thu Oct 30, 2008 4:54 pm

Re: PrintStream println() doesn't cause new line

Postby skoehler » Sun Nov 24, 2013 8:53 pm

kostas wrote:This code is running on the NXT. I'm accessing the file via nxjbrowse and view it with the Notepad.


I can confirm that Notepad will only interpret \r\n as a linebreak. But the NXT's println method generates only a \n - no \r.
Download and install Notepad++

kostas
New User
Posts: 6
Joined: Thu Nov 14, 2013 1:31 am

Re: PrintStream println() doesn't cause new line

Postby kostas » Sun Nov 24, 2013 9:41 pm

You are both wonderful, thank you very much for the help. Off to download Notepad++.


Return to “NXJ Software”

Who is online

Users browsing this forum: Baidu [Spider], Yahoo [Bot] and 3 guests