Hi,
All I want is to have the equivalent of C / C + + where you can create a file access mode "a" (there is also a + r, r + w, w +).
If I am not mistaken you speak of fopen () function which is used in C.
has : Opens the file for writing. The file is created if it did not exist. The stream is positioned at the end of the file.
So "a" stands for write access with the append at the end of the file, and that is what fair FileOutputStream when you use the constructor with parameter append to true.
In summary, I want to create a file and not make it accessible even to read, only when I finished writing this file, ie after I closed.
Accessible to whom? For other programs, know that the "a" of fopen () does not block read access to the file from other applications. If still it is what you want to do it you must use the FileLock obtained from FileChannel for your OuputStream:
Code:
FileOutputStream fout = new FileOutputStream(filename, true);
FileLock lock = fout.getChannel().lock();
try {
/ / Write file
} finally {
lock.release();
}
But the lock depends on the operating system and can vary from one platform to another.
Bookmarks