Java File Output Stream Example
We can write the file content by using File Output Stream .
File Output Stream writes the stream of raw bytes to the file.
File output Stream writes the data by using the write() method.
File output Stream Example:
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
//write the file content using File OutputStream.
public class FileOutputStreamExample {
public static void main(String[] args) {
FileOutputStream fos = null;//<i>File Output Stream</i>
File fileName = null;
try {
fileName = new File("C:\\core.txt");
fileName.createNewFile();
fos = new FileOutputStream(fileName);
fos.write("Hello Write this content".getBytes());
fos.flush();
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
if (fos != null){
fos.close();
fos = null;
}
} catch (IOException ex) {
ex.printStackTrace();
}
}
}
}
0 comments:
Post a Comment