From b6978c6c68ed72670cc6ee3d6f2e699c393bf48d Mon Sep 17 00:00:00 2001 From: Joel Dice Date: Fri, 14 Jan 2011 11:26:00 -0700 Subject: [PATCH] always create file if necessary in Java_java_io_FileOutputStream_open Previously, we would only create the file if it did not already exist *and* we weren't appending. Now we do so whether appending or not. --- classpath/java-io.cpp | 4 +++- test/FileOutput.java | 14 +++++++------- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/classpath/java-io.cpp b/classpath/java-io.cpp index f3463e25b8..740d5199c6 100644 --- a/classpath/java-io.cpp +++ b/classpath/java-io.cpp @@ -624,7 +624,9 @@ Java_java_io_FileOutputStream_open(JNIEnv* e, jclass, jstring path, jboolean app { string_t chars = getChars(e, path); if (chars) { - int fd = doOpen(e, chars, append ? (O_WRONLY | O_APPEND) : (O_WRONLY | O_CREAT | O_TRUNC)); + int fd = doOpen(e, chars, append + ? (O_WRONLY | O_CREAT | O_APPEND) + : (O_WRONLY | O_CREAT | O_TRUNC)); releaseChars(e, path, chars); return fd; } else { diff --git a/test/FileOutput.java b/test/FileOutput.java index db4273f650..fa2cc0965e 100644 --- a/test/FileOutput.java +++ b/test/FileOutput.java @@ -4,14 +4,9 @@ import java.io.File; import java.io.IOException; public class FileOutput { - - /** - * @param args - * @throws IOException - */ - public static void main(String[] args) throws IOException { + private static void test(boolean appendFirst) throws IOException { try { - FileOutputStream f = new FileOutputStream("test.txt"); + FileOutputStream f = new FileOutputStream("test.txt", appendFirst); f.write("Hello world!\n".getBytes()); f.close(); @@ -37,4 +32,9 @@ public class FileOutput { } } + public static void main(String[] args) throws IOException { + test(false); + test(true); + } + }