You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by dmhatre <da...@gmail.com> on 2012/07/05 16:42:24 UTC

Help with newline while writing to the file.

Hi Folks,
   Need help adding newline while writing to the file.
I am writing very large file using Apache Camel's File Component.
I am using StringBuffer to store very large string and then passing (passing
string ex.getIn().setBody(stringbuffer.toString()); )  it to the 
file endpoint (<to uri="file:c://cameldata/loanet/outbound"/>)
This works fine and the file is created. But when I append "\n" newline
character
the newline character is displayed as it is in notepad and other editors.
Is it possible to print the data in next line instead?

for(int i=0;i<=10;i++){
    stringbuffer.append("some records \n");
}
 

--
View this message in context: http://camel.465427.n5.nabble.com/Help-with-newline-while-writing-to-the-file-tp5715554.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Help with newline while writing to the file.

Posted by Henryk Konsek <he...@gmail.com>.
>    Need help adding newline while writing to the file.
> I am writing very large file using Apache Camel's File Component.
> I am using StringBuffer to store very large string and then passing (passing
> string ex.getIn().setBody(stringbuffer.toString()); )  it to the
> file endpoint (<to uri="file:c://cameldata/loanet/outbound"/>)

What about using Stream component [1] for that purpose? Instead of
caching lines in StringBuffer you can send them to the file as they
arrive.

from("seda:linesQueue").to("stream:file?fileName=outputFile");

This is more message-oriented-middleware way of handling large output files :) .

[1] http://camel.apache.org/stream.html

-- 
Henryk Konsek
http://henryk-konsek.blogspot.com

Re: Help with newline while writing to the file.

Posted by Christian Müller <ch...@gmail.com>.
It works for me on OSX. You may have to use '\r\n' if your OS in Windows...
And by the way, you know you can use
System.getProperty("line.separator");...

Best,
Christian

On Thu, Jul 5, 2012 at 4:42 PM, dmhatre <da...@gmail.com> wrote:

> Hi Folks,
>    Need help adding newline while writing to the file.
> I am writing very large file using Apache Camel's File Component.
> I am using StringBuffer to store very large string and then passing
> (passing
> string ex.getIn().setBody(stringbuffer.toString()); )  it to the
> file endpoint (<to uri="file:c://cameldata/loanet/outbound"/>)
> This works fine and the file is created. But when I append "\n" newline
> character
> the newline character is displayed as it is in notepad and other editors.
> Is it possible to print the data in next line instead?
>
> for(int i=0;i<=10;i++){
>     stringbuffer.append("some records \n");
> }
>
>
> --
> View this message in context:
> http://camel.465427.n5.nabble.com/Help-with-newline-while-writing-to-the-file-tp5715554.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>