aspose file tools*
The moose likes Java in General and the fly likes Line Feed Carriage Return problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Line Feed Carriage Return problem" Watch "Line Feed Carriage Return problem" New topic
Author

Line Feed Carriage Return problem

Carlos Mendoza
Greenhorn

Joined: Sep 14, 2009
Posts: 22
Hi
Do you know how to print a Line feed carriage return character not using "\n"
i am trying to generate a text file (plain) and the "\n" character doesn't work, the charset is UTF-8

this my code



and the unicode characters fails too (doesn't compile).
Thanks in advance!
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41877
    
  63
I don't quite understand why you can't use \n (both CR and LF are part of UTF-8), but ".append((char) 10)" and ".append((char) 13)" would append those two characters.


Ping & DNS - my free Android networking tools app
Carlos Mendoza
Greenhorn

Joined: Sep 14, 2009
Posts: 22
Thanks for your answer Ulf, neither do I.
i try your code and nothing happen!
I'm not understand why the "\n" doesn´t works.
Ok i'll give you more info. i'm trying to generate a plain file and send it as response from an action this is how im try to do that:



the getLayout method returns the string that will be the report.
and the getIs method returns the info as bytes for response to the client (FYI Struts 2 framework).

if i display the response in a browser it works fine.

thanks for your help

P.d this is the right forum right?
Carlos Mendoza
Greenhorn

Joined: Sep 14, 2009
Posts: 22
Oh ok all right!

i change the order of append((char) 10).append((char) 13) to append((char) 13).append((char) 10) and works fine!
thank you Dittmer!
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18570
    
    8

You'll find it a lot more convenient to go back to the original style and write that as
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19696
    
  20

Paul Clapham wrote:You'll find it a lot more convenient to go back to the original style and write that as

I agree. (char)10 is the same as '\n' and (char)13 is the same as '\r'. Your code does nothing more than append these two characters. Appending "\r\n" will do exactly the same.

Off-topic: I've seen the following code written by a professional. It made me cringe:
Suffice to say I simply replaced it with "\r\n" and I was happy again.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10378
    
    8

Whats wrong with line.separator?


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
Jelle Klap
Bartender

Joined: Mar 10, 2008
Posts: 1763
    
    7

Maneesh Godbole wrote:Whats wrong with line.separator?


Because the value of the property is platform specific. If you want to guarantee that the generated file will always contain lines that are delimited by the \r\n character sequence the line.separator property will trip you up on certain platforms.


Build a man a fire, and he'll be warm for a day. Set a man on fire, and he'll be warm for the rest of his life.
Carlos Mendoza
Greenhorn

Joined: Sep 14, 2009
Posts: 22
mmm well i'll try the orignal style
 
Don't get me started about those stupid light bulbs.
 
subject: Line Feed Carriage Return problem