Then I reset the FileConnection to a file under the photos directory.
but I can’t reset the FileConnection to photos directory again. Why?
try fileconnection.setFileConnection("..") for this.
As per API doc
public void setFileConnection(java.lang.String fileName)
Resets this FileConnection object to another file or directory. This allows reuse of the FileConnection object for directory traversal. The current FileConnection object must refer to a directory, and the new file or directory must exist within this directory, or may be the string ".." used to indicate the parent directory for the current connection). The FileConnection instance object remains open and available for use, referring now to the newly specified file or directory.
fileName - name of the file or directory to which this FileConnection is reset. The fileName must be one of the values returned from the list(String, boolean) method, or the string ".." to indicate the parent directory of the current connection. The fileName must not contain any additional path specification; i.e. the file or directory must reside within the current directory.
java.lang.NullPointerException - if fileName is null.
java.lang.SecurityException - if the security of the application does not have the security access to the specified file or directory as requested in the Connector.open method invocation that originally opened this FileConnection.
java.lang.IllegalArgumentException - if fileName contains any path specification or does not yet exist.
java.io.IOException - if the current FileConnection is opened on a file, the connection's target is not accessible, or fileName is an invalid filename for the platform (e.g. contains characters invalid in a filename on the platform).
ConnectionClosedException - if the connection is closed.