|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--waba.io.Stream | +--waba.io.File
File is a file or directory.
The File class will work in Windows CE or in a Palm OS >= 3.5, containing
an expansion card. Use the isAvailable
method to determine if the device
has or not support for file systems.
Note that in Palm OS, writting to a storage card can be slower than writting to the main memory.
Here is an example showing data being read from a file:
File file = new File("/temp/tempfile", File.READ_ONLY); if (!file.isOpen()) return; byte b[] = new byte[10]; file.readBytes(b, 0, 10); file.close(); file = new File("/temp/tempfile", File.DONT_OPEN); file.delete();
Field Summary | |
static int |
ATTR_ARCHIVE
Used in the getAttributes and setAttributes method. |
static int |
ATTR_HIDDEN
Used in the getAttributes and setAttributes method. |
static int |
ATTR_READ_ONLY
Used in the getAttributes and setAttributes method. |
static int |
ATTR_SYSTEM
Used in the getAttributes and setAttributes method. |
static int |
CREATE
Create open mode. |
static int |
DONT_OPEN
Don't open the file mode. |
int |
lastError
On device, stores the last error. |
protected String |
path
The path that represents this file |
static int |
READ_ONLY
Read-only open mode. |
static int |
READ_WRITE
Read-write open mode. |
static byte |
TIME_ACCESSED
Used in the getAttributes and setAttributes method. |
static byte |
TIME_ALL
Used in the setTime method, in parameter whichTime. |
static byte |
TIME_CREATED
Used in the getAttributes and setAttributes method. |
static byte |
TIME_MODIFIED
Used in the getAttributes and setAttributes method. |
static int |
WRITE_ONLY
Write-only open mode. |
Constructor Summary | |
File(String path)
Opens a file in DONT_OPEN mode. |
|
File(String path,
int mode)
Opens a file with the given name and mode. |
Method Summary | |
boolean |
close()
Closes the file. |
boolean |
createDir()
Creates a directory. |
boolean |
delete()
Deletes the file or directory. |
boolean |
exists()
Returns true if the file exists and false otherwise. |
int |
getAttributes()
Gets this file attributes. |
String |
getPath()
Return the file's path. |
int |
getSize()
Returns the size of the file in bytes. |
Time |
getTime(byte whichTime)
Gets the time for the given time type. |
static boolean |
isAvailable()
Returns true if a File System is available in the current PDA. |
boolean |
isDir()
Returns true if the file is a directory and false otherwise. |
boolean |
isOpen()
Returns true if the file is open for reading or writing and false otherwise. |
String[] |
listFiles()
Lists the files contained in a directory. |
int |
readBytes(byte[] b,
int off,
int len)
Reads bytes from the file into a byte array. |
boolean |
rename(String path)
Renames the file. |
void |
setAttributes(int attr)
Sets this file attributes. |
boolean |
setPos(int pos)
Sets the file pointer for read and write operations to the given position. |
void |
setTime(byte whichTime,
Time time)
Sets the time for the given time type. |
int |
writeBytes(byte[] b,
int off,
int len)
Writes to the file. |
Methods inherited from class java.lang.Object |
equals,
getClass,
hashCode,
notify,
toString,
wait,
wait |
Field Detail |
protected String path
public int lastError
For Palm OS, the list of possible errors are described below:
BufferOverflow | 10753 | ||||||||
FileGeneric | 10754 | ||||||||
FileBadRef | 10755 | ||||||||
FileStillOpen | 10756 | ||||||||
FilePermissionDenied | 10757 | ||||||||
FileAlreadyExists | 10758 | ||||||||
FileEOF | 10759 | ||||||||
FileNotFound | 10760 | ||||||||
VolumeBadRef | 10761 | ||||||||
VolumeStillMounted | 10762 | ||||||||
NoFileSystem | 10763 | ||||||||
BadData | 10764 | ||||||||
DirNotEmpty | 10765 | ||||||||
BadName | 10766 | ||||||||
VolumeFull | 10767 | ||||||||
Unimplemented | 10768 | ||||||||
NotADirectory | 10769 | ||||||||
IsADirectory | 10770 | ||||||||
DirectoryNotFound | 10771 | ||||||||
NameShortened | 10772 |
Constructor Detail |
public File(String path, int mode)
Note that the filename must not contain accentuated characters. Also, the slash / MUST be the path separator.
path
- the file's pathmode
- one of DONT_OPEN, READ_ONLY, WRITE_ONLY, READ_WRITE or CREATEpublic File(String path)
Method Detail |
public static boolean isAvailable()
public boolean close()
public boolean createDir()
public boolean delete()
public boolean exists()
public int getSize()
public String getPath()
public boolean isDir()
public boolean isOpen()
public String[] listFiles()
public int readBytes(byte[] b, int off, int len)
buf
- the byte array to read data intostart
- the start position in the arraycount
- the number of bytes to readpublic boolean rename(String path)
public boolean setPos(int pos)
file.setPos(file.getSize());True is returned if the operation is successful and false otherwise.
public int writeBytes(byte[] b, int off, int len)
buf
- the byte array to write data fromstart
- the start position in the byte arraycount
- the number of bytes to writepublic void setAttributes(int attr)
attr
- one ore more ATTR_xxx constants ORed together. Values different from the ATTR_xxx constants are simply ignored.public int getAttributes()
public void setTime(byte whichTime, Time time)
public Time getTime(byte whichTime)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |