1

I'm trying to read a file using the known 'read' method by the FileInputStream class into a certain byte[] buffer with a specific size (e.g 1024). Right after filling that buffer I'd like to validate it's characters (lets say one by one) but I don't want to convert it to a String (or use regex) since I might lose data.

Could anyone advice me what's the best way doing that specific validation? Note: I know I can use Character.isLetter and such methods but I'm not sure how to iterate that buffer.

4

1 回答 1

0

我认为这应该涵盖您想要做的事情:

byte[] arr = new byte[1024];
int len = System.in.read(arr);
while (len != -1)
{
  for (int i = 0; i < len; i++)
    System.out.println((char)arr[i] + " - " + Character.isLetter((char)arr[i]));
  len = System.in.read(arr);
}
于 2013-02-28T09:06:03.580 回答