博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
2019-3-6
阅读量:7164 次
发布时间:2019-06-29

本文共 1855 字,大约阅读时间需要 6 分钟。

package com.io;import java.io.File;import java.io.FileInputStream;import java.io.FileNotFoundException;import java.io.FileOutputStream;import java.io.IOException;import java.util.Scanner;public class FileDome {        public static void fuz (String s,String b) {        String a = "";        int du = -1;        FileInputStream  file = null;        FileOutputStream fio = null;        try {              file = new FileInputStream(s);            System.out.println("这个文件的字节是:"+file.available());            while((du=file.read())!=-1) {                    a+=(char)du;            }            System.out.println(a);            System.out.println("读取完成,准备复制");             fio = new FileOutputStream(b);            byte fuz[] = a.getBytes();            fio.write(fuz, 0, fuz.length);            System.out.println("复制完成");        } catch (FileNotFoundException e) {            e.printStackTrace();        } catch (IOException e) {            e.printStackTrace();        }finally {                if(file!=null) {                try {                    file.close();                } catch (IOException e) {                    e.printStackTrace();                }            }            if(fio!=null) {                try {                    fio.close();                } catch (IOException e) {                    e.printStackTrace();                }            }        }            }    public static void main(String[] args) {        Scanner sc = new Scanner(System.in);        System.out.println("请输入要文件的地址");        String shuru = sc.next();        File  f = new File (shuru);        if(f.exists()) {            System.out.println("请输入要要复制的地址");            String fuz = sc.next();            fuz(shuru,fuz);        }else {            System.out.println("文件不存在");        }            }}

 

输出结果图:

 

转载于:https://www.cnblogs.com/cxlbzdcom/p/10485450.html

你可能感兴趣的文章