0

I am trying to figure out how to check for carriage returns in a string. I am reading file contents into a string variable, and need to check if x0D is present (carriage return). I have tried indexOf and matcher so far with no results.

Any input would be helpful.

Thanks

2
Contributors
3
Replies
4
Views
7 Years
Discussion Span
Last Post by masijade
0

Try using '\r' with indexOf. The other thing that would help us is knowing how you're reading the file. If you are using "readLine" then \r \n \r\n are taken as line endings and stripped from the returned String.

Edited by masijade: typo "use" instead of "us"

0

Try using '\r' with indexOf. The other thing that would help use is knowing how you're reading the file. If you are using "readLine" then \r \n \r\n are taken as line endings and stripped from the returned String.

That is precisely my problem then. I am using readline to read the file. Forgive me, I am a .NET transplant and am new to Java. What way would I read the file so as to retain all the non-printable characters?

Thanks

0

One of the simple read methods.

FileInputStream fis = new FileInputStream("file");
String text = "";
byte[] buf = new byte[8192];
int read = 0;
while ((read = fis.read(buf)) >= 0) {
  text += new String(buf, 0, read);
}
fis.close();

As a simple example.

Edited by masijade: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.