ObjectOutputStream doesn't write text, it writes binary.
Hasan Diwan wrote:
> On 15/08/07, pompeez <kaj...@gm...> wrote:
>> I need to write a Java Array/ArrayList/List to a text file in Jython. I used
>> the .write() function, but it is letting me write only a string.
> Make sure the elements contained in the ArrayList implement
> java.io.Serializable and then:
> from java.io import File, ObjectOutputStream, FileOutputStream
> # ArrayList a = ArrayList()
> # a.add(1)
> # ...
> f=File.createTempFile("prefix", ".ext")
> fos=FileOutputStream(f)
> oos=ObjectOutputStream(fos)
> oos.writeObject(a)
> oos.flush()
> oos.close()
> fos.close()
> f.deleteOnExit(0)
> print f.name+'\n'
> Hope that's sorted.
|