byte[] to string?

Hello! and thank you in advance.

I am performing a search of a (huge) text file. I found it to be most efficient in searching to convert the search String to a byte[] array, open up the file as a FileInputStream, and search the Stream byte-by-byte against the search String byte[] array.

Having done this, I can confirm that the string does appear in the file. Is it possible to create a string (or char[] ) containing the 2000 characters following my search string? How?

[491 byte] By [Bacter23a] at [2007-11-26 16:47:15]
# 1
the file IS big enough that any attempt to turn it into a string overloads the heap.... just saying
Bacter23a at 2007-7-8 23:14:43 > top of Java-index,Java Essentials,New To Java...
# 2
If You are sure they all are ASCII why not to use char[] from the very beginning?If not how do You suppose to transform it to String?So, I guess char[] is more sutable here. Try cast if don't want to rewrite.
_Dima_a at 2007-7-8 23:14:43 > top of Java-index,Java Essentials,New To Java...
# 3

> Having done this, I can confirm that the string does

> appear in the file. Is it possible to create a string

> (or char[] ) containing the 2000 characters following

> my search string? How?

Wouldn't that simply be a matter of continuing to read bytes and storing them in a large enough byte array? The byte array can then be converted to a String with 'new String(byte[ ])'.

EvilBroa at 2007-7-8 23:14:43 > top of Java-index,Java Essentials,New To Java...
# 4
turns out it would. thank you very much!
Bacter23a at 2007-7-8 23:14:43 > top of Java-index,Java Essentials,New To Java...