platform/shared/rubyJVM/src/j2me/io/File.java in rhodes-2.0.0.beta2 vs platform/shared/rubyJVM/src/j2me/io/File.java in rhodes-2.0.0.beta3

- old
+ new

@@ -6,10 +6,16 @@ * Permission to use, copy, modify, and distribute this software is * freely granted, provided that this notice is preserved. */ package j2me.io; +import java.io.IOException; + +import com.rho.FilePath; +import com.rho.RhoClassFactory; +import com.rho.file.IFileAccess; + import j2me.lang.UnsupportedOperationException; /** * Class provided for the sole purpose of compiling the FileFilter and * FilenameFilter interfaces. @@ -45,22 +51,44 @@ if ((prefixLength > 0) && (_path.length() > prefixLength)) return _path.substring(0, prefixLength); return null; } return _path.substring(0, index); - } - - public boolean exists() { - throw new UnsupportedOperationException( - "File operations not supported for J2ME build"); } - public boolean isDirectory() { - throw new UnsupportedOperationException( - "File operations not supported for J2ME build"); + public String getName() + { + if ( _path == null || _path.length() == 0) + return ""; + + int index = _path.lastIndexOf('/'); + if ( index < 0 ) + index = _path.lastIndexOf('\\'); + + if ( index < 0 ) + return _path; + + return _path.substring(index+1, _path.length()); } + + public boolean exists() + { + try + { + String strPath = _path; + if (!strPath.startsWith("file:")) + strPath = FilePath.join(RhoClassFactory.createFile().getDirPath(""), strPath); + + com.rho.file.IRAFile fs = RhoClassFactory.createFSRAFile(); + fs.open(strPath); + return fs.exists(); + }catch(Exception exc) + { + return false; + } + } - public String getName() { + public boolean isDirectory() { throw new UnsupportedOperationException( "File operations not supported for J2ME build"); } public File[] listFiles() {