Loading

File类

输入输出流,用try,catch包裹起来

public class OutputStreamDemo{
    public static void main(String[] args){
        File file = new File("aaa.txt");
        OutputStream outputStream = null;
        try{
            outputStream = new FileOutputStream(file);
            outputStream.write(99);
            outputStream.write("gogogo".getBytes());
        }catch(FileNotFoundException e){
            e.printStackTrace();
        }catch(IOException e){
            e.printStackTrace();
        }finally{
            try{
                outputStream.close();
            }catch(IOException e){
                e.printStackTrace();
            }    
        }
    }
}

 

posted @ 2020-12-30 13:59  BigBender  阅读(32)  评论(0编辑  收藏  举报