zoukankan      html  css  js  c++  java
  • Java中FileOutputStream和FileInputStream使用例子

    package a.ab;
    
    import java.io.FileInputStream;
    import java.io.FileNotFoundException;
    import java.io.FileOutputStream;
    import java.io.IOException;
    
    public class AC {
        int s = 0;
    
        public static void main(String[] args) {
    
            FileOutputStream fos = null;
            try {
                fos = new FileOutputStream("D:\DD\ff.txt");
            } catch (FileNotFoundException e2) {
                // TODO Auto-generated catch block
                e2.printStackTrace();
            }
            try {
                fos.write("ddsfs山東高速費勝多負少v是vsdf".getBytes());
            } catch (IOException e1) {
                e1.printStackTrace();
            }
            try {
                if (fos != null) {
                    fos.close();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
            try {
                FileInputStream fis = new FileInputStream("D:\DD\ff.txt");
                byte[] by = new byte[1024];
                int b = 0;
                try {
                    while ((b = fis.read(by)) != -1) {
                        System.out.println(new String(by, 0, b));
                    }
                } catch (IOException e) {
                    e.printStackTrace();
                } finally {
                    if (fis != null) {
                        try {
                            fis.close();
                        } catch (IOException e) {
                            e.printStackTrace();
                        }
                    }
                }
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            }
        }
    }
    View Code
  • 相关阅读:
    判断当前时间为星期几
    springboot+mysql数据源切换
    表单上传图片
    po,vo,bo,dto,dao解释
    生成电脑的SSH key
    单例模式
    事物的特性和隔离级别
    springAOP自定义注解讲解
    Spring依赖注入(DI)的三种方式
    redis持久化
  • 原文地址:https://www.cnblogs.com/LYL-1314/p/5721077.html
Copyright © 2011-2022 走看看