zoukankan      html  css  js  c++  java
  • java 流 写

    package 流;
    
    import java.io.BufferedWriter;
    import java.io.FileNotFoundException;
    import java.io.FileOutputStream;
    import java.io.FileWriter;
    import java.io.IOException;
    import java.io.OutputStream;
    public class 写 {
        
        public static String path="d://test.txt";
        public static void main(String[] args) {
            BufferedWriterDemo();
        }
        
        //字节流
        public static void OutputStream(){
            
            try {
                OutputStream outputStream=new FileOutputStream(path);
                String str="hello world";
                byte[] b=str.getBytes();
                for(int i=0; i<b.length; i++)
                    try {
                        outputStream.write(b[i]);
                    } catch (IOException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
            } catch (FileNotFoundException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
        
        //字符流
        public static void FileWriterDemo(){
            FileWriter fileWriter;
            try {
                fileWriter = new FileWriter(path);
                String str="hello word";
                fileWriter.write(str);
                fileWriter.flush();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
        
        //缓冲流
        public static void BufferedWriterDemo(){
            BufferedWriter bufferedWriter;
            try {
                bufferedWriter = new BufferedWriter(new FileWriter(path));
                String str="hello word";
                bufferedWriter.write(str);
                bufferedWriter.flush();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
    
        }
    }
  • 相关阅读:
    openssl 生成pfx
    webpack 编译时,提示 Unexpected token: keyword «const»
    .net core 使用 Serilog 作为日志提供者
    k近邻算法
    vscode 无法自动补全第三方库
    centos 7 安装 RabbitMQ
    .net core 发布程序命令(自带运行环境)
    安装node-sass
    .net core 拦截socket
    SDN第三次作业
  • 原文地址:https://www.cnblogs.com/huangcongcong/p/4003724.html
Copyright © 2011-2022 走看看