On Thu, 30 Sep 1999, ALPESH KOTHARI wrote:

> Hello,
> 
> What you told is perfectly true. But  in my case it is
> a different story! When I read only characters then
> also it create the problem. To rectify it I have
> modified my program and now I am reading only few
> characters from the file(i.e. not going till end of
> file). Then also the same problem persists. 

No, it is the same story.
Look here:

                                        int len1=din.readByte();
                                        System.out.println(len1);
                                        byte[] lent=new byte[len1+2];
                                                             ^^^^^^
                                        for(int i=0;i<(len1-3);i++)
                                                      ^^^^^^^^
                                        {
                                                lent[i]=din.readByte();
                                                System.out.print(lent[i]);
                                                System.out.print(" ");
                                        }

Your code is incorrect.  To read in len1 bytes, your array only needs to
be exactly that long.  Java is not C/C++.

Your code should read:

byte[] lent=new byte[len1];
for (int i=0; i < len1; i++)

Then things will work perfectly.

As Wei points out in another message, if you allocate a longer array, the
other parts of the array are filled with null bytes.  When converted to
a String, the string gets null characters in it which will choke
Postgresql.

That'll be US$20 =)

. . . Sean.



----------------------------------------------------------------------
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]

Reply via email to