首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >文件选择后找不到的文件

文件选择后找不到的文件
EN

Stack Overflow用户
提问于 2017-10-05 05:27:01
回答 1查看 132关注 0票数 1

首先,如果这是一个简单的错误,我想道歉。我大多是自学成才,我所知道的是令人难以置信的零星,而且很可能是偶然的。

我正在开发一个作为密码管理器的应用程序。它具有备份和恢复功能。我让它使用一个没有问题的固定目录,但是在尝试添加文件选择器时,出现了一些问题。

保存文件位置时没有任何问题。然后,在它验证它是否被保存后,一行表示该文件不存在。这是相关的代码以及错误日志。我只会将代码包含到崩溃中,下面的内容是无关的,但可以在询问时提供。PSync.psbk是试图被读取的文件。坦白说,我不知道出了什么问题,但我认为这很简单。

代码:

代码语言:javascript
复制
 Toast.makeText(Main.this, "Method properly called.", Toast.LENGTH_SHORT).show();
                //The file variable to imported.
                File file;

                try {
                    //Sets the file equal to the file found at the specified path.
                    //Used to access settings.
                    TinyDB database = new TinyDB(getApplicationContext());

                    String strfilePath = database.getString("FilePath");
                    Toast.makeText(Main.this, "Method properly called: " + strfilePath, Toast.LENGTH_SHORT).show();
                    file = new File(strfilePath);

                    //To be used to arrange the imported information.
                    ArrayList<String> strAcc = new ArrayList<>();
                    ArrayList<String> strUser = new ArrayList<>();
                    ArrayList<String> strPass = new ArrayList<>();
                    ArrayList<String> strAdditionalInfo = new ArrayList<>();

                    //To be used to store all the information for additional info variables. This is
                    //due to its multi-line nature requiring a slightly different method of 
                    //importation, the other variables are expected to be one line.
                    String strExtraInfo = "";

                    //Goes through the file and adds info to arrays for each corresponding variable.
                    //If the line does not have an identifier, it assumes it to be an additional
                    //info line, and will be processed later.
                    try (BufferedReader br = new BufferedReader(new FileReader(file))) {  //Line 776, as mentioned in err log.

错误日志:

代码语言:javascript
复制
 W/System.err: java.io.FileNotFoundException: /document/storage/emulated/0/Download/PSync.psbk (No such file or directory)
    10-04 21:16:32.843 19405-19405/com.example.brand.psync W/System.err:     at java.io.FileInputStream.open(Native Method)
    10-04 21:16:32.843 19405-19405/com.example.brand.psync W/System.err:     at java.io.FileInputStream.<init>(FileInputStream.java:146)
    10-04 21:16:32.843 19405-19405/com.example.brand.psync W/System.err:     at java.io.FileReader.<init>(FileReader.java:72)
    10-04 21:16:32.843 19405-19405/com.example.brand.psync W/System.err:     at com.example.brand.psync.Main.onRequestPermissionsResult(Main.java:776)
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-10-05 05:36:18

您要访问的路径是:

/document/storage/emulated/0/Download/PSync.psbk

在您的路径中不应该有领先的/document。存储路径时可能会出现问题。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/46578415

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档