Dim raf As RandomAccessFile.
raf.Initialize(Dir, File, False)
raf.WriteB4XObject(rows, raf.CurrentPosition)
'read
Dim rows As List = raf.ReadB4XObject(0)
Private matrix As List
raf.Initialize(File.DirApp, "1.dat", False)
raf.WriteB4XObject(matrix, 0)
Waiting for debugger to connect...
Program started.
Saving changes...
Error occurred on line: 662
java.lang.RuntimeException: This method does not support arrays of primitives.
at anywheresoftware.b4a.randomaccessfile.B4XSerializator.writeObject(B4XSerializator.java:214)
at anywheresoftware.b4a.randomaccessfile.B4XSerializator.WriteObject(B4XSerializator.java:102)
at anywheresoftware.b4a.randomaccessfile.RandomAccessFile.WriteB4XObject(RandomAccessFile.java:295)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at anywheresoftware.b4a.shell.Shell.runVoidMethod(Shell.java:656)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:232)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:159)
at sun.reflect.GeneratedMethodAccessor2.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:93)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:90)
at anywheresoftware.b4a.BA$2.run(BA.java:165)
at com.sun.javafx.application.PlatformImpl.lambda$null$173(PlatformImpl.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$174(PlatformImpl.java:294)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$148(WinApplication.java:191)
at java.lang.Thread.run(Thread.java:745)
'fos , oos, fis, ois are all javaobjects
Dim fname As String = "C:/temp/testdata.dat" 'name of file for data
fos.InitializeNewInstance("java.io.FileOutputStream",Array(fname))
oos.InitializeNewInstance("java.io.ObjectOutputStream",Array(fos))
' ar in the next line is the 2 dimensional Double array
' I just made it (2,3) but anysize should work
oos.RunMethod("writeObject",Array(ar)) ' write the data
oos.RunMethod("close",Null) ' close output object stream
fos.RunMethod("flush",Null) ' flush the file output buffer
fos.RunMethod("close",Null) ' close output file
' these lines read it back into new array (to prove it works)
fis.InitializeNewInstance("java.io.FileInputStream",Array(fname))
ois.InitializeNewInstance("java.io.ObjectInputStream",Array(fis))
Dim yy(2,3) As Double ' the new array for the data from file
yy = ois.RunMethod("readObject",Null) ' read the object
ois.RunMethod("close",Null) ' close the object input stream
fos.RunMethod("close",Null) ' close the file input stream
' this just shows the data read from the file
For a = 0 To 1
For b = 0 To 2
Log("("&a&","&b&") "&yy(a,b))
Next
Next