File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes I/O and Streams and the fly likes How to remove carriage returns when writing to a text file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "How to remove carriage returns when writing to a text file" Watch "How to remove carriage returns when writing to a text file" New topic
Author

How to remove carriage returns when writing to a text file

Jonathan Haybok
Greenhorn

Joined: Mar 12, 2009
Posts: 16
Then can someone tell me why this isn't removing carriage returns when writing to a text file? I'm new to I/O.



Andrey Kozhanov
Ranch Hand

Joined: Mar 12, 2010
Posts: 79
Your problem is not in IO area, but in regular expressions area. Different programs even within single operating system could have different line separators. So to replace them all use not

but
Greg Charles
Sheriff

Joined: Oct 01, 2001
Posts: 2833
    
  11

Do you mean your code is replacing new lines, but not carriage returns? That's probably because your system line.separator is just a new line, but your Strings have both carriage return and new line. Try changing to:


and see if that works. Even better would be to come up with a regular expression that would match all possible line endings you might get embedded into those strings.

ETA: Oh, well, Andrey beat me to it. I believe that solution would also convert a tab to a space though, and maybe multiple spaces to a single space, which may or may not be a problem.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to remove carriage returns when writing to a text file
 
Similar Threads
New Quiz Card Builder/Player for Exam Study
How to add a line break in a text file?
QuizCard class not found. (Head First Java 2nd Ed)
Getting my main class and GUI components to talk without inner classes
Runtime Error in Program for Unknown Reasons