mirror of
https://github.com/corda/corda.git
synced 2025-01-05 20:54:13 +00:00
add ability to append to files
This commit is contained in:
parent
f0f35a920f
commit
1daa93d3c4
@ -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 {
|
||||
|
@ -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;
|
||||
|
||||
|
23
test/FileOutput.java
Normal file
23
test/FileOutput.java
Normal file
@ -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();
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user