I wanna know that size of char array is 1000 so why does read method returns -1 second time.
Because the input stream contains no more characters to read. Note that if there were a second read, you would overwrite the contents already read into the array.
And your javadoc points to the wrong method. You use the read()
method taking a char[]
as an argument. A CharBuffer
is not a char[]
!
Finally (and you have asked a question about such a subject recently and I have already told you that), you should specify the encoding you are using for both reading the file and writing to the file.