Meaningless Drivel is fun!
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
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

need to ^M at end of file

Shardul Vyawahare

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.

Stephan van Hulst

Joined: Sep 20, 2010
Posts: 4616

^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

Joined: Oct 01, 2001
Posts: 2968

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

Joined: Sep 20, 2010
Posts: 4616

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:
subject: need to ^M at end of file
It's not a secret anymore!