This week's book giveaway is in the OCAJP 8 forum.
We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line!
See this thread for details.
The moose likes I/O and Streams and the fly likes need to ^M at end of file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA Java SE 8 Programmer I Study Guide this week in the OCAJP 8 forum!
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "need to ^M at end of file" Watch "need to ^M at end of file" New topic
Author

need to ^M at end of file

Shardul Vyawahare
Greenhorn

Joined: Dec 30, 2010
Posts: 8
Hi All,

I am not familiar with Unix. I am creating a text file through the my Java code. Now my client want me to add ^M character at end of file so he will identify end of file in Unix env. How to add ^M in file is it any escape seq char . does he mean to add "\r\n" at the end ?

Please help.

SH
Stephan van Hulst
Bartender

Joined: Sep 20, 2010
Posts: 4094
    
  18

^M is just carriage return, so the Java equivalent would be '\r'.


The mind is a strange and wonderful thing. I'm not sure that it will ever be able to figure itself out, everything else, maybe. From the atom to the universe, everything, except itself.
Greg Charles
Sheriff

Joined: Oct 01, 2001
Posts: 2956
    
  12

The normal UNIX/Linux/Max OSX line separator in just "\n". It's Windows that uses "\r\n", so your client might not have that right. Also, it's a line separator, not a file ender. There's no file ending character in UNIX. DOS used to use ^Z, but I haven't seen that in a long time.
Stephan van Hulst
Bartender

Joined: Sep 20, 2010
Posts: 4094
    
  18

I was thinking that maybe the fact that carriage return is not used in UNIX would allow it to be a custom file ending character for the client's file format?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: need to ^M at end of file
 
It's not a secret anymore!