86 |
* illegal value |
* illegal value |
87 |
* @exception SecurityException If the requested access to the file |
* @exception SecurityException If the requested access to the file |
88 |
* is not allowed |
* is not allowed |
89 |
* @exception IOException If any other error occurs |
* @exception FileNotFoundException If the file is a directory, or |
90 |
|
* any other error occurs |
91 |
*/ |
*/ |
92 |
public RandomAccessFile (File file, String mode) |
public RandomAccessFile (File file, String mode) |
93 |
throws FileNotFoundException |
throws FileNotFoundException |
94 |
{ |
{ |
|
this (file.getPath(), mode); |
|
|
} |
|
|
|
|
|
/** |
|
|
* This method initializes a new instance of <code>RandomAccessFile</code> |
|
|
* to read from the specified file name with the specified access mode. |
|
|
* The access mode is either "r" for read only access, "rw" for read |
|
|
* write access, "rws" for synchronized read/write access of both |
|
|
* content and metadata, or "rwd" for read/write access |
|
|
* where only content is required to be synchronous. |
|
|
* <p> |
|
|
* Note that a <code>SecurityManager</code> check is made prior to |
|
|
* opening the file to determine whether or not this file is allowed to |
|
|
* be read or written. |
|
|
* |
|
|
* @param fileName The name of the file to read and/or write |
|
|
* @param mode "r", "rw", "rws", or "rwd" |
|
|
* |
|
|
* @exception IllegalArgumentException If <code>mode</code> has an |
|
|
* illegal value |
|
|
* @exception SecurityException If the requested access to the file |
|
|
* is not allowed |
|
|
* @exception FileNotFoundException If any other error occurs |
|
|
*/ |
|
|
public RandomAccessFile (String fileName, String mode) |
|
|
throws FileNotFoundException |
|
|
{ |
|
95 |
int fdmode; |
int fdmode; |
96 |
if (mode.equals("r")) |
if (mode.equals("r")) |
97 |
fdmode = FileChannelImpl.READ; |
fdmode = FileChannelImpl.READ; |
110 |
else |
else |
111 |
throw new IllegalArgumentException ("invalid mode: " + mode); |
throw new IllegalArgumentException ("invalid mode: " + mode); |
112 |
|
|
113 |
|
final String fileName = file.getPath(); |
114 |
|
|
115 |
// The obligatory SecurityManager stuff |
// The obligatory SecurityManager stuff |
116 |
SecurityManager s = System.getSecurityManager(); |
SecurityManager s = System.getSecurityManager(); |
117 |
if (s != null) |
if (s != null) |
122 |
s.checkWrite(fileName); |
s.checkWrite(fileName); |
123 |
} |
} |
124 |
|
|
125 |
ch = new FileChannelImpl (fileName, fdmode); |
ch = new FileChannelImpl (file, fdmode); |
126 |
fd = new FileDescriptor(ch); |
fd = new FileDescriptor(ch); |
127 |
out = new DataOutputStream (new FileOutputStream (fd)); |
out = new DataOutputStream (new FileOutputStream (fd)); |
128 |
in = new DataInputStream (new FileInputStream (fd)); |
in = new DataInputStream (new FileInputStream (fd)); |
129 |
} |
} |
130 |
|
|
131 |
/** |
/** |
132 |
|
* This method initializes a new instance of <code>RandomAccessFile</code> |
133 |
|
* to read from the specified file name with the specified access mode. |
134 |
|
* The access mode is either "r" for read only access, "rw" for read |
135 |
|
* write access, "rws" for synchronized read/write access of both |
136 |
|
* content and metadata, or "rwd" for read/write access |
137 |
|
* where only content is required to be synchronous. |
138 |
|
* <p> |
139 |
|
* Note that a <code>SecurityManager</code> check is made prior to |
140 |
|
* opening the file to determine whether or not this file is allowed to |
141 |
|
* be read or written. |
142 |
|
* |
143 |
|
* @param fileName The name of the file to read and/or write |
144 |
|
* @param mode "r", "rw", "rws", or "rwd" |
145 |
|
* |
146 |
|
* @exception IllegalArgumentException If <code>mode</code> has an |
147 |
|
* illegal value |
148 |
|
* @exception SecurityException If the requested access to the file |
149 |
|
* is not allowed |
150 |
|
* @exception FileNotFoundException If the file is a directory or |
151 |
|
* any other error occurs |
152 |
|
*/ |
153 |
|
public RandomAccessFile (String fileName, String mode) |
154 |
|
throws FileNotFoundException |
155 |
|
{ |
156 |
|
this (new File(fileName), mode); |
157 |
|
} |
158 |
|
|
159 |
|
/** |
160 |
* This method closes the file and frees up all file related system |
* This method closes the file and frees up all file related system |
161 |
* resources. Since most operating systems put a limit on how many files |
* resources. Since most operating systems put a limit on how many files |
162 |
* may be opened at any given time, it is a good idea to close all files |
* may be opened at any given time, it is a good idea to close all files |