tags:

views:

52

answers:

2

I have some data values(of type TimePrimitive) which i need to write out to a file , but the method out.write() takes only the parameter as int so i need to find a way to convert my values to int

A: 

Have you tried the getValue() method?

BTW, What platform are you using, Javascript itself does not have a TimePrimitive type, are you sure this isn't Java?

AnthonyWJones
yeah , sorry I just entered Javascript by mistake, it is Java, the method getValue() did work but it gives me this exception >>java.lang.IndexOutOfBoundsException:
sorry the method getValue() didn't work, so any other suggestion?
+1  A: 

I think it is the wrong approach. If you want to write objects to a file, then you need to use an ObjectOutputStream to write to the file:

FileOutputStream fos = new FileOutputStream("t.tmp");
ObjectOutputStream oos = new ObjectOutputStream(fos);
oos.writeInt(12345);
oos.writeObject("Today");
oos.writeObject(new Date());
    oos.writeObject(myTimePrimitive);
oos.close();

The normal out.write(int) is used to write a simple byte to a stream, and it would be implicitely be used by the ObjectOutputStream class.

You can use an ObjectInputStream to read your object back.

Mario Ortegón