Android Question Usb folder path

postasat

Active Member
Licensed User
Longtime User
Hi,
I need to use in my app a folder path located on Usb stick.
Usually, for internal file, I use dialogs library and ShowOnlyFolders to choose the correct folder.

Is the usb main path always the same if I connect different stick ?

How can I open a filedialog with filepath always set to usb "main folder" ?
Is it possible ?

I need to write text file data to specific usb folder (textwriter) folder created if needed, and reload the same text data file from the same usb folder, later.

Thank you.
 

DonManfred

Expert
Licensed User
Longtime User
Upvote 0

postasat

Active Member
Licensed User
Longtime User
Hi DonManfred,

the code I was using for internal text file was this:

B4X:
'open file data
    TR1.Initialize(File.OpenInput(foldertoload, filetoload))
                
    'read data
    data1 =  TR1.ReadLine
    data2 =  TR1.ReadLine
    data3 =  TR1.ReadLine
    data4 =  TR1.ReadLine
    data5 =  TR1.ReadLine

    listafile = TR1.ReadList
        TR1.Close

How can I modify it to use with externalstorageclass ?

Thank you.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Accessing the USB storage is a bit more complicated. Start with running the example and being able to access the USB storage.

The next step is to call FindFile to get an ExternalFile that points to the relevant file, and call OpenInputStream to open the stream. From that point the code is identical to your code.
 
Upvote 0

postasat

Active Member
Licensed User
Longtime User
Thank you,
I did it !

B4X:
'open external file USB
        Storage.OpenInputStream(Storage.FindFile(GetCurrentFolder,filelist))
        
        'read file
        TR1.Initialize(File.OpenInput(foldertoload, filelist))

:)
 
Upvote 0
Top