Check file is available or not in android?
I use the below code to create a file in my application.I need to check is the file is exist or not from my code ? Help me
FileOutputStream fOut = null;        
    OutputStreamWriter osw = null;
    String data="My file Test ";  
    try{
        fOut = openFileOutput("settings.dat",MODE_PRIVATE);     
        osw = new OutputStreamWriter(fOut);
        osw.write(data);
        osw.flush();           
        }
        开发者_如何转开发catch (Exception e) {      
        e.printStackTrace();          
        }
Have you tried the File.exists() method?
public boolean exists()
- Tests whether the file or directory denoted by this abstract pathname exists.
Returns:
trueif and only if the file or directory denoted by this abstract pathname exists;falseotherwise
(Basically, you would do something like if (new File("settings.dat").exists()) { ... }.)
Otherwise, you could go through Context.fileList() and look for the file there.
 
         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论