java.lang.Object | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| | - | - | java.io.OutputStream | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| | - | - | java.io.FileOutputStream | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
A file output stream is an output stream for writing data to a File or to a FileDescriptor.
Constructor | Summary |
---|---|
FileOutputStream(File file) | Creates a file output stream to write to the file represented by the specified File object. |
FileOutputStream(File file, boolean append) | Creates a file output stream to write to the file represented by the specified File object. |
FileOutputStream(FileDescriptor fdObj) | Creates an output file stream to write to the specified file descriptor, which represents an existing connection to an actual file in the file system. |
FileOutputStream(String name) | Creates an output file stream to write to the file with the specified name. |
FileOutputStream(String name, boolean append) | Creates an output file stream to write to the file with the specified name. |
Return | Method | Summary |
---|---|---|
void | close() | Closes this file output stream and releases any system resources associated with this stream. |
FileChannel | getChannel() | Returns the unique FileChannel object associated with this file output stream. |
FileDescriptor | getFD() | Returns the file descriptor associated with this stream. |
void | write(byte[] b) | Writes b.length bytes from the specified byte array to this file output stream. |
void | write(byte[] b, int off, int len) | Writes len bytes from the specified byte array starting at offset off to this file output stream. |
void | write(int b) | Writes the specified byte to this file output stream. |
Create FileOutputStream object from File object
import java.io.File;
import java.io.FileOutputStream;
public class Main {
public static void main(String[] args) throws Exception {
File file = new File("C:/demo.txt");
FileOutputStream fos = new FileOutputStream(file);
}
}
Write file using FileOutputStream
import java.io.FileOutputStream;
public class Main {
public static void main(String[] args) throws Exception {
FileOutputStream fos = new FileOutputStream("C:/demo.txt");
byte b = 01;
fos.write(b);
fos.close();
}
}
java2s.com | Contact Us | Privacy Policy |
Copyright 2009 - 12 Demo Source and Support. All rights reserved. |
All other trademarks are property of their respective owners. |