How to get file separators used by different file systems?

Good afternoon everyone

From what I understand, Android has (at least) 2 file systems. One for "internal" storage (for example, / data and / system), and the other for "external" storage (for example / mnt / sdcard),

This means that when saving files to internal storage ( Context.getFilesDir , Context.getCacheDir ), the file separator used may be different than when we save files to external storage ( Context.getExternalFilesDir , Context.getExternalCacheDir , Environment.getExternalStoragePublicDirectory ) , but java.io.File.separator only seems to give us information about the default file system used.

How do we get different file separators used by different file systems on Android?

I tried java.nio.file.spi.FileSystemProvider.installedProviders () , but it looks like android does not have this package .

Is there a way to get a list of file systems on Android?

+4
source share
2 answers

From what I understand, Android has (at least) 2 file systems. One for "internal" storage (for example, / data and / system), and the other for "external" storage (for example / mnt / sdcard),

This was accurate for Android 1.x and 2.x. Starting with Android 3.0, external storage is just a directory inside the internal storage.

This means that when saving files to internal storage (Context.getFilesDir, Context.getCacheDir), the file separator used may be different from when we save files to "external" storage

Of course not. Separators are a function of the operating system, not a file system.

Is there a way to get a list of file systems on Android?

Nothing is supported. SDK applications should only use internal and external storage, for example, through the APIs that you indicated in your answer.

Hmm, I heard about mounting an external drive on NTFS, so I think they can be different

You are wrong. File and path delimiters have nothing to do with the file system format.

However, its not only file separators, file separators (path separators) also differ between different file systems.

You are wrong. File and path delimiters have nothing to do with the file system format.

+4
source

If you are worried about placing a hard file encoder in your code, you can use File.separator instead of hardcoded "/". This will give you the file separator used by Android without worrying about which file system is under it.

+3
source

Source: https://habr.com/ru/post/1399859/


All Articles