On Tuesday 19 November 2002 14:44, Pauwels Stefan wrote:
> I'm new to Jython and I try to write my first script.
> I could not found any good tutorial on this.
> I have the following code (suppose InputStream comes from somewhere:
> isr =3D InputStreamReader (InputStream)
> c =3D String("")
> output =3D isr.read(c, 0 ,256)
> i =3D 0
> while (output !=3D -1) :
> i =3D i+1
> output =3D isr.read(c,i*256, 256)
> This piece doesn't work,
> it gives an error:
> TypeError: read(): 1st arg can't be coerced to char
A java.lang.String is immutable, so there is no way of reading into it.
You need to use a char, an array of characters:
import jarray # java array module
ca =3D jarray.zeros(100, 'c') # 100 zero characters
bytesRead =3D isr.read(ca)
pythonString =3D ca[:bytesRead].tostring()