Byte output stream FileOutputStream

### Byte output stream FileOutputStream

  1. FileOutputStream:
    is the output stream used to write files. In addition to the functions defined by the base class, it also implements the abstract function of OutputStream write(int b): write(int b): convert b into a byte data, Write to the output stream.

2. FileOutputStream is an output stream used to write files, so it needs a file as an instantiation parameter.
This file can be a File object or a file path string. (If the file does not exist, it will be created automatically.)
(The second parameter can be given when FileOutputStream is instantiated. The second parameter is whether to use append write default. When it is true
, it means to append data to the original file content. The default is false)

package mine;

import java.io.FileOutputStream;
import java.io.IOException;

/**
 * @author MXL
 *字节输出流 FileOutputStream
 */
/*
 *1. FileOutputStream:
 * 是用于写文件的输出流,它除了可以使用基类定义的函数外,
 * 还实现了OutputStream的抽象函数write(int b):
 * write(int b):将b转成一个字节数据,写到输出流中。
 * 
 * 2.FileOutputStream是用于写文件的输出流,所以它需要一个文件作为实例化参数,
 * 这个文件可以是File对象,也可以是文件路径字符串。【如果文件不存在,那么将自动创建。】
 * 【FileOutputStream实例化时可以给第二个参数,第二个参数是是否使用追加写入默认,为true
 * 时代表在原有文件内容后面追加写入数据,默认为false】
 * 
 */
public class FileOutPutStreamTest {
    
    
	public static void main(String[] args) {
    
    
		try {
    
    
			FileOutputStream fos =new FileOutputStream("mine/1.txt");
			fos.write("Hello zi chuan".getBytes());
			fos.close();
			
			
		} catch (IOException e) {
    
    
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}
}

Guess you like

Origin blog.csdn.net/LL__Sunny/article/details/108524148