Android Question How to write to external USB storage?

Meuke

Member
Licensed User
Hello,
I am trying to write a file to an external USB stick.
The problem is that I get an error "java.io.FileNotFoundException: /storage/6233-3230/gsi/METING_Cloud_1_16.gsi (Permission denied)"
What I can do is check for the presence of a directory on the external USB device.
Writing to the external USB stick results in an error -> Permission denied.
Can someone help me out on this one?

B4X:
Sub FindUsbDevice As String
    'CHECK - UsbStorage
    If (File.Exists("/storage/6233-3230/gsi", "") = True) Then
        Return "/storage/6233-3230/gsi Directory was found"
        
        Write_2_File("/storage/6233-3230/Gsi/", strBestandsUit_gsi , Resultaat_AES_Decrypt)
        
    Else
        Return "Error : Directory gsi was not found"
    End If
End Sub


Sub Write_2_File(DirTarget As String, FileTarget As String,Text_string As String) As String
    Dim My_txt_Writer As TextWriter
    Dim data_out As String
    data_out = Text_string
    My_txt_Writer.Initialize(File.OpenOutput(DirTarget,FileTarget,False))
    My_txt_Writer.Write(data_out)
    My_txt_Writer.Close
    Return data_out
    
End Sub
 

Meuke

Member
Licensed User
In the program example above it returned "/storage/6233-3230/gsi Directory was found"
This means that the directory "/storage/6233-3230/Gsi/" could be found on the usb device...
 
Upvote 0
Top