java文件复制

java文件复制

 	public static void copy(String startPath,String endPath)throws IOException {
        long start = System.currentTimeMillis();
        //创建读取流
        FileInputStream fis = new FileInputStream(startPath);
        //创建写入流
        FileOutputStream fos = new FileOutputStream(endPath,true);
        //创建读取缓冲流
        BufferedInputStream bis = new BufferedInputStream(fis);
        //创建写入缓冲流
        BufferedOutputStream bos = new BufferedOutputStream(fos);
        //使用缓冲流来读取文件
        byte[] bytes = new byte[1024];
        int len = 0;
        while ((len = bis.read(bytes))!=-1){
            bos.write(bytes,0,len);
        }
        bos.close();
        bis.close();
        long end = System.currentTimeMillis();
        System.out.println("耗时:"+(end-start));
    }
    //播放音频文件
    public static void play(String path) throws IOException, JavaLayerException {
        FileInputStream fis = new FileInputStream(path);
        BufferedInputStream bis = new BufferedInputStream(fis);
        Player player = new Player(bis);
        player.play();
        bis.close();
    }
    public static void main(String[] args) throws IOException,JavaLayerException{
        copy("./a.mp3","D:/a.mp3");
        play("D:/a.mp3");
    }
posted @ 2022-10-08 11:20  彼时听风  阅读(91)  评论(0)    收藏  举报