70 |
* on this stream. |
* on this stream. |
71 |
*/ |
*/ |
72 |
private boolean error; |
private boolean error; |
73 |
|
|
74 |
|
/** |
75 |
|
* Indicates whether or not the stream has been closed. |
76 |
|
*/ |
77 |
|
private boolean closed; |
78 |
|
|
79 |
/** |
/** |
80 |
* This is the underlying <code>Writer</code> we are sending output |
* This is the underlying <code>Writer</code> we are sending output |
143 |
this.autoflush = autoflush; |
this.autoflush = autoflush; |
144 |
} |
} |
145 |
|
|
146 |
/** @since 1.5 */ |
/** |
147 |
public PrintWriter(String path) |
* This initializes a new PrintWriter object to write to the specified |
148 |
throws FileNotFoundException |
* file. It creates a FileOutputStream object and wraps it in an |
149 |
{ |
* OutputStreamWriter using the default encoding. |
150 |
this(new OutputStreamWriter(new FileOutputStream(path))); |
* @param file name of the file to write to |
151 |
|
* @throws FileNotFoundException if the file cannot be written or created |
152 |
|
* |
153 |
|
* @since 1.5 |
154 |
|
*/ |
155 |
|
public PrintWriter(String file) throws FileNotFoundException |
156 |
|
{ |
157 |
|
this(new FileOutputStream(file)); |
158 |
} |
} |
159 |
|
|
160 |
/** @since 1.5 */ |
/** |
161 |
public PrintWriter(String path, String encoding) |
* This initializes a new PrintWriter object to write to the specified |
162 |
|
* file. It creates a FileOutputStream object and wraps it in an |
163 |
|
* OutputStreamWriter using the specified encoding. |
164 |
|
* @param file name of the file to write to |
165 |
|
* @param enc the encoding to use |
166 |
|
* @throws FileNotFoundException if the file cannot be written or created |
167 |
|
* @throws UnsupportedEncodingException if the encoding is not supported |
168 |
|
* |
169 |
|
* @since 1.5 |
170 |
|
*/ |
171 |
|
public PrintWriter(String file, String enc) |
172 |
throws FileNotFoundException, UnsupportedEncodingException |
throws FileNotFoundException, UnsupportedEncodingException |
173 |
{ |
{ |
174 |
this(new OutputStreamWriter(new FileOutputStream(path), encoding)); |
this(new OutputStreamWriter(new FileOutputStream(file), enc)); |
175 |
} |
} |
176 |
|
|
177 |
/** @since 1.5 */ |
/** |
178 |
public PrintWriter(File path) |
* This initializes a new PrintWriter object to write to the specified |
179 |
throws FileNotFoundException |
* file. It creates a FileOutputStream object and wraps it in an |
180 |
|
* OutputStreamWriter using the default encoding. |
181 |
|
* @param file the file to write to |
182 |
|
* @throws FileNotFoundException if the file cannot be written or created |
183 |
|
* |
184 |
|
* @since 1.5 |
185 |
|
*/ |
186 |
|
public PrintWriter(File file) throws FileNotFoundException |
187 |
{ |
{ |
188 |
this(new OutputStreamWriter(new FileOutputStream(path))); |
this(new FileOutputStream(file)); |
189 |
} |
} |
190 |
|
|
191 |
/** @since 1.5 */ |
/** |
192 |
public PrintWriter(File path, String encoding) |
* This initializes a new PrintWriter object to write to the specified |
193 |
|
* file. It creates a FileOutputStream object and wraps it in an |
194 |
|
* OutputStreamWriter using the specified encoding. |
195 |
|
* @param file the file to write to |
196 |
|
* @param enc the encoding to use |
197 |
|
* @throws FileNotFoundException if the file cannot be written or created |
198 |
|
* @throws UnsupportedEncodingException if the encoding is not supported |
199 |
|
* |
200 |
|
* @since 1.5 |
201 |
|
*/ |
202 |
|
public PrintWriter(File file, String enc) |
203 |
throws FileNotFoundException, UnsupportedEncodingException |
throws FileNotFoundException, UnsupportedEncodingException |
204 |
{ |
{ |
205 |
this(new OutputStreamWriter(new FileOutputStream(path), encoding)); |
this(new OutputStreamWriter(new FileOutputStream(file), enc)); |
206 |
} |
} |
207 |
|
|
208 |
/** |
/** |
225 |
*/ |
*/ |
226 |
public boolean checkError() |
public boolean checkError() |
227 |
{ |
{ |
228 |
flush(); |
if (! closed) |
229 |
|
flush(); |
230 |
return error; |
return error; |
231 |
} |
} |
232 |
|
|
253 |
{ |
{ |
254 |
try |
try |
255 |
{ |
{ |
256 |
out.close(); |
out.close(); |
257 |
|
closed = true; |
258 |
} |
} |
259 |
catch (IOException ex) |
catch (IOException ex) |
260 |
{ |
{ |