2014-04-29 3 views
-1

나는 파일 -파일이 Android에 존재하는지 여부를 찾는 방법은 무엇입니까?

FileOutputStream fos = context.openFileOutput("MyFile",Context.MODE_PRIVATE); 

ObjectOutputStream os = new ObjectOutputStream(fos); 

//Saving my list 
os.writeObject(EmailStackClass.list); 
os.close(); 

은 내가 어떻게 식별 할 수있는이 파일이 이미 존재하는 경우 작성하는 다음과 같은 코드를 작성해야? 이전에 파일을 만든 경우 이전 데이터에 데이터를 추가해야합니다. 제발 도와주세요 ... 코드 아래

+2

Welcome to StackOv erflow! 제발, 새로운 질문을 만들기 전에 둘러보십시오 ... http://stackoverflow.com/questions/16237950/android-check-if-file-exists-without-creating-a-new-one –

+0

http : // stackoverflow .com/a/16238204/1665507 그것을 확인하십시오. –

답변

1

시도는 : -

File f = new File("MyFile"); // PATH OF YOUR FILE 
     if(f.exists()) 
     { 
      System.out.println("file exist"); 
     } 
     else 
     { 
      System.out.println("file not exist"); 
     } 
+0

나는 항상 파일이 존재하지 않는다. – user2166895

+0

@ user2166895 IT는 파일이 없다는 것을 의미한다 !!! – duggu

0
다음과 같이 확인할 수 있습니다

은 ...

File file = getBaseContext().getFileStreamPath(fileName); 
if(file.exists()) { 

    //do something with the existed file 
} 
0

먼저이 옵션을 선택합니다 ..

File file = new File("dirPath", "fileName"); 
if(file.exists()){ 
     // file exists 
}else{ 
     // file not exists 
} 

이 도움이되기를 바랍니다 ..

+0

dirPath, – user2166895

+0

을 어떻게 알았습니까? 그 파일을 어떻게 만들었습니까? –

+0

FileOutputStream ("MyFile", \t ObjectOutputStream os = 새 ObjectOutputStream (fos); os.writeObject (EmailStackClass.list); os.close(); – user2166895

관련 문제