나는이 코드를 android에 작성하여 .txt 파일의 존재 여부를 확인했습니다.파일이 있는지 여부를 어떻게 알 수 있습니까?
File file_a =new File("a.txt");
InputStream in3 = getResources().openRawResource(R.raw.b);
FileOutputStream out3 = null;
try { out3=openFileOutput("a.txt",Context.MODE_WORLD_WRITEABLE);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
byte[] buff3 = new byte[1024];
int read3 = 0;
try {
while ((read3 = in3.read(buff3)) > 0) {
out3.write(buff3, 0, read3);
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
try {
in3.close();
out3.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
boolean a=file_a.exists();
항상 false
을 반환합니다.
어떻게 해결할 수 있습니까?
파일이 저장된 위치를 읽을 권한이 있습니까? –
나는 당신이 당신의 안드로이드 장치의 루트 디렉토리에 글을 쓰는 것을 허락 받았는지 의심 스럽다. 반환 값은 올바른 것입니다. – WarrenFaith
이해가 안되니? 파일이 존재합니다. 나는 값을 읽었습니다. 그러나 부울 a는 거짓입니까? 방법 것입니다? 파일이 존재합니다 –