tags:

views:

590

answers:

1

How to read a very big data using DataInputStream of socket If the data is in String format and having a length of more than 1,00,000 characters.

Also How to write that big data using SocketChannel in java

Thanks Deepak

+1  A: 

The problem is that your data is arriving in chunks. Either the packet size is limiting that or maybe DataInputStream has an internal buffer of only 40k. I don't know, but it doesn't matter. Either way, all 1000000 bytes will not arrive at once. So you have to rewrite your program to expect that. You need to read the smaller chunks that you receive and store them in another byte[1000000] variable (keeping track of where your last byte index). Keep looping until you are done reading the socket. Then you can work with your internal variable.

Hi Chris,There is some situation when I am getting my read data is 0 although the whole data is not received yet. So how to overcome from this problem.Can you give some examples.
Deepak