First of, the Path.Combine
will not create the file if it's not existed on the android. So I used the FileStream
to create it.
string filePath = Path.Combine(FileSystem.AppDataDirectory, "test.jpg");using (FileStream fileStream = new FileStream(filePath, FileMode.OpenOrCreate)){}
And then, the File.Delete(filePath)
work well in my project. The output in my project:
// Output: File Exist!
And I have used the Device File Explorer in the Android Studio to check the result: The file will be deleted after File.Delete(filePath)
excuted.
The environment I used:
- Visual Studio 17.11.0 Preview 2.1
- .Net 8.0
- Test on both Android 10 emulator and XiaoMi physical device with Android 14.0