먼저 단순한 오류가 발생하면 사과드립니다. 나는 대부분 스스로 독학을하고, 내가 아는 것은 믿을 수 없을 정도로 산발적이며 우연이 될 수 있습니다.파일을 가져온 후 파일을 찾을 수 없습니다.
저는 암호 관리자로 작동하는 앱을 만들고 있습니다. 그것은 백업 및 복원 기능이 있습니다. 문제없이 고정 된 디렉토리를 사용하여 작업 할 수있게되었지만 파일 선택기를 추가 할 때 문제가있었습니다.
파일 위치가 문제없이 저장됩니다. 그런 다음 한 줄에 파일이 저장되었음을 확인한 후 파일이 존재하지 않는다고 표시됩니다. 오류 로그뿐만 아니라 관련 코드도 있습니다. 나는 충돌에 코드를 포함시킬 것인데, 그 뒤에 오는 것은 부적절하지만 질문을 받으면 제공 될 수 있습니다. PSync.psbk는 읽으려고하는 파일입니다. 솔직히 뭘 잘못했는지는 모르겠지만 간단하다고 가정합니다.
코드 :
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.
ERR 로그 :
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)
매니페스트에서 허가를 받았습니다 –
예, 가지고 있으며 런타임 권한도 요청합니다. file = new File (Environment.getExternalStoragePublicDirectory (Environment.DIRECTORY_DOWNLOADS), "PSync.psbk") 형식의 파일을 읽는 데 아무런 문제가 없습니다. – Prometheus
@NabinBhandari 예,이 코드 스 니펫은 onRequestPermissionsResult 안에 있습니다. 코드는 권한이 부여 된 후에 만 실행됩니다. Amrutha에게 말했듯이, Environmemnt.get 메소드를 사용할 때 동일한 디렉토리에서 같은 파일을 읽는 데 문제가 없습니다. – Prometheus