Java基础知识强化之IO流笔记17:FileOutputStream构造方法使用

时间:2023-05-07 17:17:16

1. 可以参照之前写的笔记:   Android(java)学习笔记167:Java中操作文件的类介绍(File + IO流)

2. FileOutputStream(常用的)构造方法:

FileOutputStream(File file)
          Constructs a new FileOutputStream on the File file.

FileOutputStream(String filename)
          Constructs a new FileOutputStream on the file named
filename.

3. 代码示例:

 package com.himi.fileoutputstream;

 import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream; /*
*
* 构造方法摘:
* FileOutputStream(String filename)
* Constructs a new FileOutputStream on the file named filename.
*
* FileOutputStream(File file)
* Constructs a new FileOutputStream on the File file.
*
*/ public class FileOutputStreamDemo { public static void main(String[] args) throws FileNotFoundException {
//FileOutputStream(File file)
File file = new File("fos.txt");
FileOutputStream fos = new FileOutputStream(file); //FileOutputStream(String filename)
FileOutputStream fos1 = new FileOutputStream("fos.txt"); } }