diff --git a/classpath/java-io.cpp b/classpath/java-io.cpp index 22880146ac..134045bdd2 100644 --- a/classpath/java-io.cpp +++ b/classpath/java-io.cpp @@ -593,11 +593,11 @@ Java_java_io_FileInputStream_close(JNIEnv* e, jclass, jint fd) } extern "C" JNIEXPORT jint JNICALL -Java_java_io_FileOutputStream_open(JNIEnv* e, jclass, jstring path) +Java_java_io_FileOutputStream_open(JNIEnv* e, jclass, jstring path, jboolean append) { string_t chars = getChars(e, path); if (chars) { - int fd = doOpen(e, chars, O_WRONLY | O_CREAT | O_TRUNC); + int fd = doOpen(e, chars, append ? (O_WRONLY | O_APPEND) : (O_WRONLY | O_CREAT | O_TRUNC)); releaseChars(e, path, chars); return fd; } else { diff --git a/classpath/java/io/FileOutputStream.java b/classpath/java/io/FileOutputStream.java index d61d44e136..5a485e04f3 100644 --- a/classpath/java/io/FileOutputStream.java +++ b/classpath/java/io/FileOutputStream.java @@ -22,14 +22,19 @@ public class FileOutputStream extends OutputStream { } public FileOutputStream(String path) throws IOException { - fd = open(path); + this(path, false); } + public FileOutputStream(String path, boolean append) throws IOException { + fd = open(path, append); + } + + public FileOutputStream(File file) throws IOException { this(file.getPath()); } - private static native int open(String path) throws IOException; + private static native int open(String path, boolean append) throws IOException; private static native void write(int fd, int c) throws IOException; diff --git a/test/FileOutput.java b/test/FileOutput.java new file mode 100644 index 0000000000..e097f18598 --- /dev/null +++ b/test/FileOutput.java @@ -0,0 +1,23 @@ +import java.io.FileOutputStream; +import java.io.IOException; + + +public class FileOutput { + + /** + * @param args + * @throws IOException + */ + public static void main(String[] args) throws IOException { + FileOutputStream f = new FileOutputStream("test.txt"); + f.write("Hello world!\n".getBytes()); + f.close(); + + FileOutputStream f2 = new FileOutputStream("test.txt", true); + f2.write("Hello world again!".getBytes()); + f2.close(); + + + } + +}