2

In my Android app, users can download files. The app modify the downloaded file right after the download completes. However, whenever the downloaded file's name includes a question mark somewhere in it, the downloaded file cannot be reached and thus cannot be modified. Related code is as follows:

String pathToFile = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS) + "/" + document.getTitle();

// Example pathToFile: /storage/emulated/0/Download/Recording ? 20171227.mp3
File downloadedFile = new File(pathToFile);

if (!downloadedFile.exists()) {
    // Always gets here if filename includes at least one '?'
}

I try adding "file://" prefix to pathToFile, converting pathToFile to Uri or URI, but nothing worked. It always says file doesn't exist. Any help is appreciated.

ADDITIONAL INFO: The document filename is retrieved from the internet and I save the document using the same filename. I can see the file with same filename in the Downloads folder, however, I cannot open it programmatically.

Mehmed
  • 2,880
  • 4
  • 41
  • 62

1 Answers1

1

As recommended by commentators, I replace #, % and ? with empty string. The following characters don't cause a problem: !@$^&*()[]{}|

Mehmed
  • 2,880
  • 4
  • 41
  • 62