• FileOutputStream将从一个文件中读取的内容写到另一个文件中


     package com.janson.day2018082

    import java.io.FileInputStream;
    import java.io.FileNotFoundException;
    import java.io.FileOutputStream;
    import java.io.IOException;
    
    public class TestFileOutputStream {
        public static void main(String[] args) {
            FileInputStream in = null;
            FileOutputStream out = null;
            int f = 0;
            int num = 0;
            try{
                in = new FileInputStream(System.getProperty("user.dir") + "/src/com/janson/day20180827/TestFileInputStream.java");
                out = new FileOutputStream("D:/javaExample/file/TestIO.java");
            }catch (FileNotFoundException e) {
                System.out.println("找不到相应文件");
            }
    
            try {
                while ((f = in.read()) != -1) {
                    out.write(f);
                    num ++;
                }
                out.flush();
    out.close(); System.out.println("写入文件成功,共写入了" + num + "个字节"); }catch (IOException e) { System.out.println("读取文件出错了"); } } }
  • 相关阅读:
    jQuery 选择器 与 事件
    JavaScript 语法
    Java 包(package)
    Java 接口
    java封装继承多态---继承篇
    Java数组的学习
    java基础周总结
    JAVA基础接口集合框架
    周总结
    Java基础
  • 原文地址:https://www.cnblogs.com/janson071/p/9605410.html
Copyright © 2020-2023  润新知