question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

download error if file exists

See original GitHub issue
/**
     * Create a file using java.io API
     */
    private File createFileInAppSpecificDir(String filename, String savedDir) {
        File newFile = new File(savedDir, filename);
        try {
            boolean rs = newFile.createNewFile();
            if (rs) {
                return newFile;
            } else {
                logError("It looks like you are trying to save file in public storage but not setting 'saveInPublicStorage' to 'true'");
            }
        } catch (IOException e) {
            e.printStackTrace();
            logError("Create a file using java.io API failed ");
        }
        return null;
    }

should add this

if (newFile.exists()) {
            return newFile;
}

Issue Analytics

  • State:open
  • Created a year ago
  • Reactions:1
  • Comments:9

github_iconTop GitHub Comments

4reactions
Faaatmancommented, May 11, 2022

This error is also happening on Android when the file is in the directory but I’m trying to download it using the downloader.

@hnvn do you think there’s a better solution for this? I think it’s better to append a duplication number to the file name ex(photo.png, photo(1).png) since different files can have the same file name and rewriting or retrieving the file with the same name isn’t the best solution IMO. I can work on a PR for this fix, I just need your input. 😃

0reactions
IlyaMaxcommented, Aug 30, 2022

you all have this open failed: EACCES (Permission denied) error? I’m not sure that I have the same issue as you but it seems like that

Read more comments on GitHub >

github_iconTop Results From Across the Web

Download and check if file exists - python
I'm not sure how to grab and check the url filename. 1 - open a text file containing a list with URLs (example.com/file.exe, ......
Read more >
How to check if a file exists (in download folder) from your App?
In this video it shows how one can check whether a file exists or not for Android 11 (API level 30) and above...
Read more >
Powershell If file exists, do nothing , else, download
If the file exists, the download should not even run, which means that the check is failing. What do you get if you...
Read more >
File Manager check if file exists before download
Implement your own logic to check if a downloaded file exists and cancel a current download operation with the corresponding error text.
Read more >
Fix file download errors - Google Chrome Help
Get help with a specific error message · Cancel the download and try again. · Instead of clicking the file to download, right-click...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found