File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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 Elasticsearch in Action this week in the Big Data 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

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: 3658

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

Joined: Oct 01, 2001
Posts: 2867

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: 3658

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?
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
subject: need to ^M at end of file