iOS Question File.OpenOutput return 'null'

nicieri

Active Member
Licensed User
Longtime User
post2 is null? what am I doing wrong?



Sub Cam_Complete (Success As Boolean, Image As Bitmap, VideoPath As String)
If Success Then
If Image.IsInitialized Then
'for image
Else
'for video
vv.View.Visible = True
vv.LoadVideo(VideoPath, "")

Dim os2 As OutputStream
Log(VideoPath)
Dim ps() As String = Regex.split("/", VideoPath)
Dim fileName As String =(ps(ps.Length-1))
Dim path As String =""
For i = 0 To ps.Length-2
path = path & ps(i) & "/"
Next

Log(path & fileName) ' this is correct
os2.InitializeToBytesArray(0)
os2 = File.OpenOutput(path,fileName,True)
os2.Close

Dim p2 As StringUtils
Dim post2 As String = p2.EncodeBase64(os2.ToBytesArray)
Log(post2) ' post2 is 'null'

End If
End If
End Sub
 
Hi Erel, Yes. I'm trying this... reading into an array of bytes..

Why my post2 is null?

Code: Copy
os2.InitializeToBytesArray(0)
os2 = File.OpenOutput(path,fileName,True)
os2.Close

This code is not working.
 
Upvote 0
There are several mistakes in this code.
1. You initialize the object and then assign a new object to the same variable. The previously object is removed.
2. File.OpenOutput opens an output stream. Output streams are used to write data to a file.

Correct code:
Code: Copy
Dim b() As Byte = Bit.InputStreamToBytes(File.OpenInput(path, fileName))
 
Upvote 0
There are several mistakes in this code.
1. You initialize the object and then assign a new object to the same variable. The previously object is removed.
2. File.OpenOutput opens an output stream. Output streams are used to write data to a file.

Correct code:
Code: Copy
Dim b() As Byte = Bit.InputStreamToBytes(File.OpenInput(path, fileName))


Thanks Erel!!
 
Upvote 0

Similar Threads

  • Locked
  • Article Article
Android Code Snippet [B4X] DownloadAndSave
Replies
2
Views
10K
Replies
77
Views
83K
Replies
36
Views
136K
  • Article Article
Android Code Snippet [B4X] Bytes To File
Replies
28
Views
68K
Back
Top