summaryrefslogtreecommitdiffstats
path: root/luni/src/main/java/java/io/FileWriter.java
diff options
context:
space:
mode:
Diffstat (limited to 'luni/src/main/java/java/io/FileWriter.java')
-rw-r--r--luni/src/main/java/java/io/FileWriter.java105
1 files changed, 105 insertions, 0 deletions
diff --git a/luni/src/main/java/java/io/FileWriter.java b/luni/src/main/java/java/io/FileWriter.java
new file mode 100644
index 0000000..63aee88
--- /dev/null
+++ b/luni/src/main/java/java/io/FileWriter.java
@@ -0,0 +1,105 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package java.io;
+
+/**
+ * A specialized {@link Writer} that writes to a file in the file system.
+ * All write requests made by calling methods in this class are directly
+ * forwarded to the equivalent function of the underlying operating system.
+ * Since this may induce some performance penalty, in particular if many small
+ * write requests are made, a FileWriter is often wrapped by a
+ * BufferedWriter.
+ *
+ * @see BufferedWriter
+ * @see FileReader
+ *
+ * @since Android 1.0
+ */
+public class FileWriter extends OutputStreamWriter {
+
+ /**
+ * Creates a FileWriter using the File {@code file}.
+ *
+ * @param file
+ * the non-null File to write bytes to.
+ * @throws IOException
+ * if {@code file} cannot be opened for writing.
+ * @since Android 1.0
+ */
+ public FileWriter(File file) throws IOException {
+ super(new FileOutputStream(file));
+ }
+
+ /**
+ * Creates a FileWriter using the File {@code file}. The parameter
+ * {@code append} determines whether or not the file is opened and appended
+ * to or just opened and overwritten.
+ *
+ * @param file
+ * the non-null File to write bytes to.
+ * @param append
+ * indicates whether or not to append to an existing file.
+ * @throws IOException
+ * if the {@code file} cannot be opened for writing.
+ * @since Android 1.0
+ */
+ public FileWriter(File file, boolean append) throws IOException {
+ super(new FileOutputStream(file, append));
+ }
+
+ /**
+ * Creates a FileWriter using the existing FileDescriptor {@code fd}.
+ *
+ * @param fd
+ * the non-null FileDescriptor to write bytes to.
+ * @since Android 1.0
+ */
+ public FileWriter(FileDescriptor fd) {
+ super(new FileOutputStream(fd));
+ }
+
+ /**
+ * Creates a FileWriter using the platform dependent {@code filename}.
+ *
+ * @param filename
+ * the non-null name of the file to write bytes to.
+ * @throws IOException
+ * if the file cannot be opened for writing.
+ * @since Android 1.0
+ */
+ public FileWriter(String filename) throws IOException {
+ super(new FileOutputStream(new File(filename)));
+ }
+
+ /**
+ * Creates a FileWriter using the platform dependent {@code filename}. The
+ * parameter {@code append} determines whether or not the file is opened and
+ * appended to or just opened and overwritten.
+ *
+ * @param filename
+ * the non-null name of the file to write bytes to.
+ * @param append
+ * indicates whether or not to append to an existing file.
+ * @throws IOException
+ * if the {@code file} cannot be opened for writing.
+ * @since Android 1.0
+ */
+ public FileWriter(String filename, boolean append) throws IOException {
+ super(new FileOutputStream(filename, append));
+ }
+}